# NullCount - 圖表函數

NullCount() 用來彙總每一個圖表維度中 null 值的數目。

語法：

NullCount({[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) |

範例：圖表運算式

| 範例 | 結果 |
| --- | --- |
| `NullCount(OrderNumber)` | 傳回 `OrderNumber` 欄位中 NULL 值的計數。 |
| ` NullCount (OrderNumber)/NullCount ({1} Total OrderNumber)  ` | 運算式會從所選客戶傳回 `OrderNumber` 為 `NULL` 的訂單數量，作為來自 `OrderNumber` 為 `NULL` 之客戶的所有訂單部分。 |

## 範例 - NullCount 基礎事項

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

#### 圖表運算式

概述

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

載入指令碼包含：

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

* 設定為 `NULL` 的 `NullInterpret` 值處理變數。該變數會將所有含有文字 `NULL` 的記錄解譯為 Null 值。

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

  * `Customer`

  * `Product`

  * `OrderNumber`

載入指令碼

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

提示備註若要將 `NullInterpret` 變數還原為預設值，請在載入指令碼末尾包含以下變數陳述式：`Set NULLINTERPRET =;`

結果

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

* `Customer`

建立下列量值：

* `=NullCount(OrderNumber)`，用來計算 `OrderNumber` 為 `NULL` 的訂單數量。

* `=NullCount (OrderNumber)/NullCount ({1} Total OrderNumber)`，用來 (從所選客戶) 傳回 `OrderNumber` 為 `NULL` 的訂單數量，作為來自 `OrderNumber` 為 `NULL` 之客戶的所有訂單部分。 若要將此值顯示為百分比，請在數字格式之下，選取數字 &gt; 簡單格式 &gt; 12.34%。

Results table

| Customer | NullCount(OrderNumber) | NullCount (OrderNumber)/NullCount ({1} Total OrderNumber) |
| --- | --- | --- |
| Totals | 3 | 100.00% |
| Astrida | 0 | 0.00% |
| Betacab | 1 | 33.33% |
| Canutility | 2 | 66.67% |

第一個量值會傳回 `3`，因為總共有 `3` 筆 `OrderNumber` 記錄具有 `NULL` 值 (`1` 筆是客戶 `Betacab` 的記錄，而 `2` 筆是 `Canutility` 客戶的記錄)。

第二個量值傳回 `NULL` 訂單數量，作為來自所有客戶的 `NULL` 訂單部分。例如，所有值為 `NULL` 的訂單數量中，有 `66.67%` 歸屬於客戶 `Canutility`。

## 範例 - 使用 NullCount 識別 KPI 資料中的 Null 值

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

#### 圖表運算式

概述

資料集包含每月的關鍵產品指標 (KPI) 資料。產品經理想要找出資料中哪些 KPI 有 Null 值。

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

載入指令碼包含：

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

* 設定為 `NULL` 的 `NullInterpret` 值處理變數。該變數會將所有含有文字 `NULL` 的記錄解譯為 Null 值。

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

  * `Month`

  * `KPI`

  * `Value`

載入指令碼

```
Set NULLINTERPRET = NULL;
Example:
LOAD * inline [
Month, KPI, Value
2024-01-01, Revenue, 5000
2024-02-01, Revenue, NULL
2024-03-01, Revenue, 5500
2024-04-01, Revenue, NULL
2024-01-01, Expenses, 3000
2024-02-01, Expenses, 3100
2024-03-01, Expenses, NULL
2024-04-01, Expenses, 3200
2024-01-01,Customer Count, 200
2024-02-01,Customer Count, 210
2024-03-01,Customer Count, NULL
2024-04-01,Customer Count, NULL
];
```

提示備註若要將 `NullInterpret` 變數還原為預設值，請在載入指令碼末尾包含以下變數陳述式：`Set NULLINTERPRET =;`

結果

載入資料並開啟工作表。建立新的樞紐分析表並將此欄位新增為列維度：

* `KPI`

建立下列量值：

* `=NullCount(Value)`，用來計算遺失值數量。

Results table

| KPI | NullCount(Value) |
| --- | --- |
| Customer Count | 2 |
| Expenses | 1 |
| Revenue | 2 |

結果顯示，資料集中有 `5` 筆記錄有 `NULL` 值，以及與這些記錄相關的 KPI 類別。