IF

IF(condition, true_branch, false_branch)[source]

Returns one of two values depending on the evaluation of a condition.

This function mimics the behavior of the Excel IF function. It evaluates the condition, and if true, returns the value of true_branch; otherwise, it returns the value of false_branch. If any input is blank or in an error state, the formula evaluates to an error.

Parameters:
  • condition (Operand | bool | int) – The condition to evaluate.

  • true_branch (Operand | bool | int | float | str) – The value to return if the condition is true. Must be the same data type as false_branch, or NULL.

  • false_branch (Operand | bool | int | float | str) – The value to return if the condition is false. Must be the same data type as true_branch, or NULL.

Return type:

Formula

Returns:

Either true_branch or false_branch, depending on the condition.

Raises:
  • ValueError – If condition is not BOOLEAN or INTEGER.

  • ValueError – If true_branch and false_branch have incompatible types (unless one is NULL).

  • ValueError – If both true_branch and false_branch are NULL.

Examples

Basic usage with literals:

result = IF(True, "Yes", "No")

Using fields and formulas:

result = IF(customer["age"] > 18, "Adult", "Minor")

Nested IF statements:

result = IF(score > 90, "A", IF(score > 80, "B", IF(score > 70, "C", "F")))

``condition`` — accepted types

  • BOOLEAN

  • INTEGER

``true_branch`` — 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

``false_branch`` — 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