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.
Supported types:
BOOLEAN
INTEGER (treats 0 as False, non-zero as True)
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.
Supported types:
ANY
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.
Supported types:
ANY
- Return type:
- Returns:
Either true_branch or false_branch, depending on the condition.
Supported types:
ANY
- 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")))