# TextCount - 圖表函數

TextCount() 用來彙總每一個圖表維度中非數值的欄位值數目。

語法：

TextCount({[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/May2026/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/define-aggregation-scope.htm) |

範例：圖表運算式

| 範例 | 結果 |
| --- | --- |
| `TextCount(Product)` | 傳回文字值形式的產品名稱數量。 |
| `TextCount(OrderNumber)` | 傳回 `OrderNumber` 欄位中具有文字值的列數。<br><br>資訊備註"0" 計為某個值，而不是空的儲存格。然而，如果某個維度的量值彙總為 0，則該維度不會包括在圖表中。 空白儲存格會評估為非文字，且不會被 `TextCount` 納入計數。 |
| `TextCount (DISTINCT Product)/Count(Product)` | 計算 `Product` 中所有不同文字值的數量，然後除以 `Product` 中的值總數。 |

## 範例 - TextCount 基礎事項

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/CounterAggregationFunctions/textcount.htm)

#### 圖表運算式

概述

開啟資料載入編輯器並將下面的載入指令碼新增至新的區段。

載入指令碼包含：

* 載入到稱為 `Example` 之資料表格的資料集。

* 資料表格中的欄位如下：

  * `Customer`

  * `Product`

  * `OrderNumber`

載入指令碼

```
Set NULLINTERPRET = ' ';
Example:
LOAD * inline [
Customer|Product|OrderNumber
Astrida|AA|1
Astrida|AA|7
Astrida|BB|4
Betacab|CC|6
Betacab|AA|5
Betacab|BB|
Canutility|AA|
Canutility|CC|
Divadip|CC|2
Divadip|DD|3
](delimiter is '|');
```

結果

載入資料並開啟工作表。建立新的表格並新增下列量值：

* `=TextCount(Product)`，用來傳回產品名稱是文字值的數量。

* `=TextCount(OrderNumber)`，用來計算訂單號碼是文字值的數量。

* `=TextCount(DISTINCT Product)/Count(Product)`，用來計算 `Product` 中相異文字值的總數，然後除以 `Product` 中的值總數。

Results table

| TextCount(Product) | TextCount(OrderNumber) | TextCount(DISTINCT Product)/Count(Product) |
| --- | --- | --- |
| 10 | 3 | 0.4 |

第一個量值傳回 `10`，因為 `Product` 中的全部十筆記錄都是文字。

第二個量值傳回 `3`，因為空儲存格被視為文字，並納入計算。通常，您可能使用此量值類型檢查數值欄位中沒有任何文字值或是空的。

第三個量值傳回 `0.4`。此結果的計算方式是將 `Product` 中相異文字值的總數 (`4`) 除以 `Product` 中的值總數 (`10`)。

## 範例 - TextCount 使用情境

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/CounterAggregationFunctions/textcount.htm)

#### 圖表運算式

概述

資料集包含調查回應資料，其中有對產品的投訴，也有對產品的一般意見回饋。您只想檢閱含有文字值的回應。

開啟資料載入編輯器並將下面的載入指令碼新增至新的區段。

載入指令碼包含：

* 載入到稱為 `Example` 之資料表格的資料集。

* 資料表格中的欄位如下：

  * `CustomerID`

  * `ProductPurchased`

  * `Complaint`

  * `Feedback`

載入指令碼

```
Set NullInterpret = '';
Example:
Load * Inline [
CustomerID, ProductPurchased, Complaint, Feedback
1, Laptop, Slow performance, "The laptop is slow, poor battery, slow graphics"
2, Mobile, Heating issue, "Mobile heats up, average camera"
3, Laptop, Battery problem, "Battery not working, slow to charge"
4, Tablet, Screen issue, "Screen is broken, unresponsive touch"
5, Mobile, No issues, "Excellent performance"
6, Mobile, 123, "123"
7, Laptop, ,
8, Tablet, Warranty expired,
9, Mobile, , "Contact customer service"
];
```

結果

載入資料並開啟工作表。建立新的表格並將這些欄位新增為維度：

* `ProductPurchased`

建立下列量值：

* `=TextCount(ProductPurchased)`，用來計算含有非數值的產品名稱數量。

* `=TextCount(Complaint)`，用來計算含有非數值的投訴數量。

* `=TextCount(Feedback)`，用來計算含有非數值的意見回饋值數量。

Results table

| ProductPurchased | TextCount(ProductPurchased) | TextCount(Complaint) | TextCount(Feedback) |
| --- | --- | --- | --- |
| Laptop | 3 | 2 | 2 |
| Mobile | 4 | 2 | 3 |
| Tablet | 2 | 2 | 1 |

結果顯示，對於產品 `Laptop`，共有 `3` 筆記錄，其中 `2` 筆有投訴，`2` 筆有意見回饋。同樣地，對於產品 `Mobile`，有 `4` 筆記錄，包括 `2` 筆投訴和 `3` 筆意見回饋。數值或空值不納入計算，因為預期 `ProductPurchased`、`Complaint` 和 `Feedback` 欄位是文字值。