Skip to content

if

if

⚡ Conditional

Return one of two values based on whether a condition is true or false

if(condition, then_value, else_value) → any
any

Returns then_value if condition is true, else_value if false; null if condition is null

The if function returns one value if a condition is true, and another value if it is false.

  • If condition is null, returns null (not then_value or else_value)
  • then_value and else_value can have different types (e.g., number and string)
  • if functions can be nested for complex logic
| eval is_error = if(status == "error", true, false)

Creates a boolean field is_error that is true if status equals “error”.

| eval severity = if(status_code >= 500, "critical", "normal")

Categorizes records as “critical” if status code is 500 or higher, otherwise “normal”.

| eval tier = if(score > 90, "gold", if(score > 70, "silver", "bronze"))

Multi-level categorization: gold (>90), silver (>70), bronze (≤70).

| eval discount = if(total_spent > 1000, total_spent * 0.1, 0)

Applies a 10% discount to customers who spent more than 1000, otherwise no discount.

| eval result_display = if(success, "OK", "FAILED")

Returns a string based on a boolean field.


See Case for a more complex conditional function with multiple branches.

  • eval — to create fields with conditional values