Skip to content

Selector functions

The following functions are available to map the values from selector variables to strings and numerics. Once mapped they can be used with any functions and operators that support those types.

A selector variable has coded categories like PostArea or Income Band. Each category has a code and a description.

An Income band category might look like this:

Code Description
00 Unclassified
01 \< 10k
02 10-20k
03 20-30k
04 30-40k

CodeOf

Returns the code of the selector variable.

Expression
CodeOf([Selector Variable])

For example, CodeOf([Income Band]) = "04"

DescOf

Returns the decode description of the selector variable.

Expression
DescOf([Selector Variable])

For example, DescOf([Income Band]) = "30 – 40k"

ValueOf

Returns the description of the selector variable as a number.

Expression
ValueOf([Selector Variable])

For example, ValueOf([Income Band]) = 30 as it just takes the first number.

IndexOf

Returns the index of the code of the selector variable as a number.

Expression
IndexOf([Selector Variable])

For example, IndexOf([Income Band]) is 4. Unclassified is zero.

InstantCountOf

Returns the 'instant count' of the selector variable as a number.

Expression
InstantCountOf([Income]) e.g. £100k+ = 53

In this example 53 people have an income of £100k+.

Populated

The variable type must be a selector, array, or flag array.

For a selector variable it returns the number of populated values, which is 1, unless the category is unclassified. For array and flag array variables, it returns the number of populated categories for that record.

For example:

Expression
Populated([Communication Channels])

This returns the number of populated communication channels for that record.

VarSelect

Returns the index of the given code for the given selector variable if the record in question has one of the code values set.

Expression
VarSelect([Income], "01", "02", "03")

1 for all records that have an Income value with code "01", 2 for all records that have an Income value with code "02", 3 for all records that have an Income value with code "03" and blank otherwise.

VarSelectNth

Expression
VarSelectNth(Number N, [Selector Variable], Code1, ...)

Using a 1-based index, returns an integer of the Nth code from the list that matches the code of the selector variable category. If there is no match then it returns 0.

For example, VarSelectNth(2, [Products Bought], "AB", "CD", "EF") returns the second selected product from the list, otherwise it will return 0.

An alternative version using lists is VarSelectNth(Number N, Selector Variable, TextList).

Cardinality of

Returns the number of category codes for selector variables.

VarDesc

Returns the description for a selector variable category.

  • VarDesc([myVar],"code") returning the description for the corresponding code

or

  • VarDesc([myVar],N) returning the description corresponding to index N

Example:

Expression
VarDesc([myVar],CreateSet(2,3))

This returns a delimited string of descriptions corresponding to the indexes in the set.

VarCode

Example:

Expression
VarCode([Selector Variable], Desc or Index)

This returns the code of the selector variable category code.

Alternatively, you can use a number to return the code corresponding to index N. The final parameter can be a numeric set which returns a delimited string of codes that correspond to the indexes in the set.

For example, VarCode([Product Code], "Plate") returns the code of the category with description "Plate" for the Product Code variable.

VarSelectCode

Returns the first matched code based on each selector variable evaluating along the parameters.

Multiple sets of selector variable and values lists can be used.

For example:

Expression
VarSelectCode ([postsect], CV34 3, CV34 4, [postdist], CV31 , [postarea], B,OX)

Specifying the optional AsDesc presents the output as descriptions, if these are available.

VarSelectCodeNth

Example:

Expression
VarSelectCodeNth(Number N, [Selector Variable], Code1, , [Selector Variable], CodeN, , )

This returns the Nth matched code based on each selector variable being checked against its own separate list of match codes.

You can use multiple sets of selector variable and values lists. You usually use this with array or flag array variables that can have multiple selected values.

By specifying an optional parameter as the string "AsDesc" at the start, you can present the output as descriptions, if these are available.

For example, VarSelectCodeNth (2, [Postal Sector], "CV34 3", "CV34 4", [Postal District], "CV31", [Postal Area], "B", "OX") looks to match the current record with the Postal Sectors, then the Postal Districts and finally the Postal Areas, and returns the second matching one.

NthSelectedFlag

Returns the description of the Nth selected flag in a flag array.

If N is negative then the Nth from last is selected

NthIndexSelectedFlag

Returns the index of the Nth selected flag in a flag array.

If N is negative then the Nth from last is selected