# GetSelectedCount

GetSelectedCount() 會找出欄位中選取值 (綠色) 的數量。

語法：

GetSelectedCount (field\_name [, include\_excluded])

傳回的資料類型： 整數

引數：

* field\_name： 包含待測量資料範圍的欄位。
* include\_excluded：若設為 True()，則計數會包括目前受其他欄位中的選項所排除的選取值。若為 False 或省略的話，就不會包括這些值。
* state\_name：輪替狀態機的名稱。如果已指定，將傳回在輪替狀態機中的欄位的經計數值。如果未提供輪替狀態機，則使用預設狀態。

下表列出了與此函數相關的其他函數。

相關函數

| 函數 | 互動 |
| --- | --- |
| [GetStateCounts](https://help.qlik.com/zh-TW/qlikview/September2026/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/getstatecounts.htm) | 使用 GetStateCounts()，您可以使用單一函數叫用合併下列計數的計算：<br><br><ul> <li> <p>所選包含值的計數。</p> </li> <li> <p>可能值的計數。</p> </li> <li> <p>已取消選取的值的計數 (僅當欄位處於 and (和) 模式時才可用)。</p> </li> <li> <p>替代值的計數。</p> </li> <li> <p>排除值的計數，不包括替代值和所選的排除值。</p> </li> <li> <p>所選排除值的計數。</p> </li> </ul> |
| [GetPossibleCount](https://help.qlik.com/zh-TW/qlikview/September2026/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/getpossiblecount.htm) | 傳回可能值的計數。 |
| [GetNotSelectedCount](https://help.qlik.com/zh-TW/qlikview/September2026/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/GetNotSelectedCount.htm) | 傳回已取消選取的值的計數 (僅當欄位處於 and (和) 模式時才可用)。 |
| [GetAlternativeCount](https://help.qlik.com/zh-TW/qlikview/September2026/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/getalternativecount.htm) | 傳回替代值的計數。 |
| [GetSelectedCount](https://help.qlik.com/zh-TW/qlikview/September2026/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/getselectedcount.htm#) | 傳回排除值的計數，不包括替代值和所選的排除值。 |

## 列表框中選取狀態的顏色

本頁所有資訊均指在具有特定設定的列表框中選取狀態的顏色：

* QlikView 文件設定為 Classic Extended 的色彩配置。請參閱： [選項外觀](https://help.qlik.com/zh-TW/qlikview/September2026/Subsystems/Client/Content/QV_QlikView/Document_Properties_General.htm#SelectionAppearance)

* 設定為開啟顯示替代選項的列表框。請參閱： [顯示替代選項](https://help.qlik.com/zh-TW/qlikview/September2026/Subsystems/Client/Content/QV_QlikView/List_Box.htm#ShowAlternatives)

下表概述了具有此設定的列表框中每個選取狀態的色彩配置。

具有給定設定的列表框的色彩配置

| 狀態 | 儲存格色彩 | 文字色彩 |
| --- | --- | --- |
| 替代 | 白色 | 灰色 |
| 已取消選取 | 紅色 | 黑色 |
| 已排除 | 灰色 | 白色 |
| 可能 | 白色 | 黑色 |
| 已選取 | 綠色 | 黑色 |
| 已選取且已排除 | 灰色 | 綠色 |

## 範例

以下範例使用載入至不同列表框的三個欄位，一個用於 First name 名稱，另一個用於 Initials，另一個則是 Has cellphone。

範例 1: 在 First name 中選取了 John

`GetSelectedCount  ([First name])`

傳回 1 因為在 First name 中選取了一個值。

範例 2: 在 First name 中選取了 John

`GetSelectedCount  ([Initials])`

傳回 0 因為在 Initials 中沒有選取任何值。

範例 3: First name 中沒有選項，Initials 中選取了所有值，而 Has cellphone 中選取了 Yes

`GetSelectedCount  ([Initials], True())`

傳回 6。雖然 InitialsMC 和 PD 選項已將 Has cellphone 設為 No，但結果仍是 6，因為引數 include\_excluded 設定為 True()。

範例中使用的資料：

`Names:` `LOAD * inline [` `"First name"|"Last name"|Initials|"Has cellphone"` `John|Anderson|JA|Yes` `Sue|Brown|SB|Yes` `Mark|Carr|MC |No` `Peter|Devonshire|PD|No` `Jane|Elliot|JE|Yes` `Peter|Franc|PF|Yes ] (delimiter is '|');`