# GetAlternativeCount

GetAlternativeCount() 用于查找所标识字段中的替代值（带灰色文本的白色单元格）的数量。

语法：

GetAlternativeCount (field\_name)

**返回数据类型：** 整数

参数：

* field\_name： 包含要度量的数据范围的字段。

下表列出了与此函数相关的其他函数。

相关函数

| 函数 | 交互 |
| --- | --- |
| [GetStateCounts](https://help.qlik.com/zh-CN/qlikview/September2025/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/getstatecounts.htm) | 使用 GetStateCounts()，您可以使用单个函数调用组合以下计数的计算：<br><br><ul> <li> <p>所选包含值的计数。</p> </li> <li> <p>可能的值计数。</p> </li> <li> <p>取消选择的值的计数（仅当字段处于“和”模式时可用）。</p> </li> <li> <p>替代值的计数。</p> </li> <li> <p>排除值的计数，不包括替代和选定的排除值。</p> </li> <li> <p>所选排除值的计数。</p> </li> </ul> |
| [GetSelectedCount](https://help.qlik.com/zh-CN/qlikview/September2025/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/getselectedcount.htm) | 返回所选包含值的计数。 |
| [GetPossibleCount](https://help.qlik.com/zh-CN/qlikview/September2025/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/getpossiblecount.htm) | 返回可能值的计数。 |
| [GetNotSelectedCount](https://help.qlik.com/zh-CN/qlikview/September2025/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/GetNotSelectedCount.htm) | 返回取消选择的值的计数（仅当字段处于和模式时可用）。 |
| [GetAlternativeCount](https://help.qlik.com/zh-CN/qlikview/September2025/Subsystems/Client/Content/QV_QlikView/ChartFunctions/FieldFunctions/getalternativecount.htm#) | 返回排除值的计数，不包括替代和选定的排除值。 |

## 列表框内选择项状态的颜色

本页面的全部信息都是指在特定设置下列表框中选择项状态的颜色：

* QlikView 文件配置为经典扩展色彩方案。请参阅： [选择项外观](https://help.qlik.com/zh-CN/qlikview/September2025/Subsystems/Client/Content/QV_QlikView/Document_Properties_General.htm#SelectionAppearance)

* 列表框配置为打开显示替代。请参阅： [显示替代项](https://help.qlik.com/zh-CN/qlikview/September2025/Subsystems/Client/Content/QV_QlikView/List_Box.htm#ShowAlternatives)

下表概述了使用此配置的列表框内各选择项状态的配色方案。

给定配置时列表框的配色方案

| 状态 | 单元颜色 | 文本颜色 |
| --- | --- | --- |
| 替代 | 白色 | 灰色 |
| 取消选择 | 红色 | 黑色 |
| 排除值 | 灰色 | 白色 |
| 可能 | 白色 | 黑色 |
| 选定 | 绿色 | 黑色 |
| 选定排除值 | 灰色 | 绿色 |

## 示例

以下示例使用加载到列表框的 First name 字段和以下语法：

`GetAlternativeCount  ([First name])`

* 鉴于 John 在 First name 中被选中，脚本会返回 4 ，因为 First name 中有 4 个唯一且排除的（灰色）值。
* 给定 John 和 Peter 被选中，脚本将返回 3，因为 First name 中有 3个唯一且排除在外的（灰色）值。
* 鉴于First name 中没有选择任何值，脚本返回0 ，因为没有选择。

示例中所使用的数据：

`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 '|');`