CHOOSE

CHOOSE(index, *values)[source]

Returns the value at a specified index from a list of inputs.

The CHOOSE function selects a value from the provided values based on the 1-based index. If the index is out of range, the formula will evaluate to an error. All input values must be of the same data type.

Parameters:
  • index (Operand | int) – The position of the value to select. Indexing starts at 1.

  • *values (Operand | str | int | float | bool) – An arbitrary number of values to choose from. All values must share the same data type.

Return type:

Formula

Returns:

A Formula object representing the selected value.

Raises:

ValueError

  • If no values are provided. - If the index is not an integer. - If the data types of the input values are inconsistent.

Examples

CHOOSE(2, "apple", "banana", "cherry")
# Returns "banana"
CHOOSE(4, "apple", "banana", "cherry")
# Returns an error value since index 4 is out of range.

``index`` — accepted types

  • BOOLEAN

  • BOOLEAN_ARRAY

  • BOOLEAN_MAP

  • DATE

  • DATETIME

  • DATETIME_ARRAY

  • DATETIME_MAP

  • DATE_ARRAY

  • DATE_MAP

  • DECIMAL

  • DECIMAL_ARRAY

  • DECIMAL_MAP

  • INTEGER

  • INTEGER_ARRAY

  • INTEGER_MAP

  • NULL

  • OBJECT

  • OBJECT_ARRAY

  • STRING

  • STRING_ARRAY

  • STRING_MAP

  • TIME

  • TIME_ARRAY

  • TIME_MAP

``value`` (variadic) — accepted types

  • BOOLEAN

  • BOOLEAN_ARRAY

  • BOOLEAN_MAP

  • DATE

  • DATETIME

  • DATETIME_ARRAY

  • DATETIME_MAP

  • DATE_ARRAY

  • DATE_MAP

  • DECIMAL

  • DECIMAL_ARRAY

  • DECIMAL_MAP

  • INTEGER

  • INTEGER_ARRAY

  • INTEGER_MAP

  • NULL

  • OBJECT

  • OBJECT_ARRAY

  • STRING

  • STRING_ARRAY

  • STRING_MAP

  • TIME

  • TIME_ARRAY

  • TIME_MAP

Return types

  • BOOLEAN

  • BOOLEAN_ARRAY

  • BOOLEAN_MAP

  • DATE

  • DATETIME

  • DATETIME_ARRAY

  • DATETIME_MAP

  • DATE_ARRAY

  • DATE_MAP

  • DECIMAL

  • DECIMAL_ARRAY

  • DECIMAL_MAP

  • INTEGER

  • INTEGER_ARRAY

  • INTEGER_MAP

  • OBJECT

  • OBJECT_ARRAY

  • STRING

  • STRING_ARRAY

  • STRING_MAP

  • TIME

  • TIME_ARRAY

  • TIME_MAP