if
if
⚡ ConditionalReturn 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.
Edge Cases
Section titled “Edge Cases”- If
conditionisnull, returnsnull(notthen_valueorelse_value) then_valueandelse_valuecan have different types (e.g., number and string)iffunctions can be nested for complex logic
Examples
Section titled “Examples”Simple Boolean Field
Section titled “Simple Boolean Field”| eval is_error = if(status == "error", true, false)
Creates a boolean field is_error that is true if status equals “error”.
Categorization
Section titled “Categorization”| eval severity = if(status_code >= 500, "critical", "normal")
Categorizes records as “critical” if status code is 500 or higher, otherwise “normal”.
Nested Conditions
Section titled “Nested Conditions”| eval tier = if(score > 90, "gold", if(score > 70, "silver", "bronze"))
Multi-level categorization: gold (>90), silver (>70), bronze (≤70).
Calculation with Condition
Section titled “Calculation with Condition”| 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.
String from Boolean Field
Section titled “String from Boolean Field”| 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.
Used In
Section titled “Used In”eval— to create fields with conditional values