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.

    Supported types:

    • INTEGER

  • *values (Operand | str | int | float | bool) –

    An arbitrary number of values to choose from. All values must share the same data type.

    Supported types:

    • ANY

Return type:

Formula

Returns:

A Formula object representing the selected value.

Supported types:

  • ANY

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.