# GetFieldSelections

GetFieldSelections() returns a string with the current selections in a field.

If all but two, or all but one of the values are selected, the format 'NOT x,y' or 'NOT y' will be used respectively. If you select all values and the count of all values is greater than max\_values, the text ALL will be returned.

Syntax:

GetFieldSelections ( field\_name [, value\_sep [, max\_values [, state\_name]]])

Return data type: string

Return string formats

| Format | Description |
| --- | --- |
| 'a, b, c' | If the number of selected values is max\_values or less, the string returned is a list of<br>the selected values.<br><br>The values are separated with value\_sep as delimiter. |
| 'NOT a, b, c' | If the number of non-selected values is max\_values or less, the string returned is a list of the non-selected values with NOT as a prefix.<br><br>The values are separated with value\_sep as delimiter. |
| 'x of y' | x = the number of selected values<br><br>y = the total number of values<br><br>This is returned when max\_values &lt; x &lt; ( y - max\_values). |
| 'ALL' | Returned if all values are selected. |
| '-' | Returned if no value is selected. |
| &lt;search string&gt; | If you have selected using search, the search string is returned. |

Arguments:

* field\_name: The field containing the range of data to be measured.
* value\_sep: The separator to be put between field values. The default is ', '.
* max\_values: The maximum number of field values to be individually listed. When a larger number of values is selected, the format 'x of y values' will be used instead. The default is 6.
* state\_name: The name of an alternate state that has been chosen for the specific visualization. If the state\_name argument is used, only the selections associated with the specified state name are taken into account. For more information, see [Alternate States](https://help.qlik.com/en-US/qlikview/September2026/Subsystems/Client/Content/QV_QlikView/Alternate%20States.htm).

## Examples

The following example uses the First name field loaded to a list box.

Example 1: John selected in First name

`GetFieldSelections ([First name])`

returns 'John'

Example 2: John and Peter selected in First name

`GetFieldSelections ([First name])`

returns 'John,Peter'

Example 3: John and Peter selected in First name

`GetFieldSelections ([First name],'; ')`

returns 'John; Peter'

Example 4: John, Sue, Mark selected in First name

`GetFieldSelections ([First name],';',2)`

returns 'NOT Jane;Peter', because the value 2 is stated as the value of the max\_values argument. Otherwise, the result would have been John; Sue; Mark.

Data used in example:

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