# Count - 圖表函數

Count() 用來彙總每一個圖表維度中值、文字及數值的數目。

語法：

Count({[SetExpression] [DISTINCT] [TOTAL [&lt;fld {,fld}&gt;]]} expr)

傳回的資料類型： 整數

引數：

引數

| 引數 | 描述 |
| --- | --- |
| expr | 包含待測量之資料的運算式或欄位。 |
| SetExpression | 依預設，彙總函數將彙總選項所定義的一組可能記錄。集合分析運算式可定義一組替代的記錄。 |
| DISTINCT | 如果 DISTINCT 這個字出現在函數引數之前，會忽略評估函數引數所產生的重複項目。 |
| TOTAL | 如果單字 TOTAL 位於函數引數之前，則會在提供現行選項的所有可能值上進行計算，而不僅僅是關於目前維度值的那些選項，也就是說，它會忽略圖表維度。<br><br>透過使用 TOTAL [&lt;fld {.fld}&gt;] (其中 TOTAL 限定詞後面是做為圖表維度變數子集之一或更多欄位名稱的清單)，您可建立總可能值的子集。<br><br>[定義彙總範圍](https://help.qlik.com/zh-TW/sense/November2024/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/define-aggregation-scope.htm) |

範例與結果：

Data

| Customer | Product | OrderNumber | UnitSales | Unit Price |
| --- | --- | --- | --- | --- |
| Astrida | AA | 1 | 4 | 16 |
| Astrida | AA | 7 | 10 | 15 |
| Astrida | BB | 4 | 9 | 9 |
| Betacab | BB | 6 | 5 | 10 |
| Betacab | CC | 5 | 2 | 20 |
| Betacab | DD | 1 | 25 | 25 |
| Canutility | AA | 3 | 8 | 15 |
| Canutility | CC |  |  | 19 |
| Divadip | AA | 2 | 4 | 16 |
| Divadip | DD | 3 |  | 25 |

以下範例假設選取了所有客戶，例外之處會另行說明。

範例與結果

| 範例 | 結果 |
| --- | --- |
| `Count(OrderNumber)` | 10，因為有 10 個欄位可能具有 OrderNumber 的值，且所有記錄 (包含空白者) 都納入計數。<br><br>資訊備註"0" 計為某個值，而不是空的儲存格。然而，如果某個維度的量值彙總為 0，則該維度不會包括在圖表中。 |
| `Count(Customer)` | 10，因為 Count 會評估所有欄位的出現次數。 |
| `Count(DISTINCT [Customer])` | 4，因為使用 Distinct 限定詞，Count 只會評估唯一的出現次數。 |
| 假定已選取客戶 Canutility<br><br><br>`Count(OrderNumber)/Count({1} TOTAL OrderNumber)` | 0.2，因為運算式會從所選客戶傳回訂單數，作為來自所有客戶的訂單百分比。此情況下為 2 / 10。 |
| 假定已選取客戶 Astrida 和 Canutility<br><br>`Count(TOTAL <Product> OrderNumber)` | 5，因為這是僅針對所選客戶產品下訂的訂單數，且空白儲存格納入計數。 |

範例中使用的資料：

`Temp:` `LOAD * inline [` `Customer|Product|OrderNumber|UnitSales|UnitPrice` `Astrida|AA|1|4|16` `Astrida|AA|7|10|15` `Astrida|BB|4|9|9` `Betacab|CC|6|5|10` `Betacab|AA|5|2|20` `Betacab|BB|1|25|  25` `Canutility|AA|3|8|15` `Canutility|CC|||19` `Divadip|CC|2|4|16` `Divadip|DD|3|1|25` `] (delimiter is '|');`