if
Returns one of two values depending on whether a condition is true or false. This is the primary conditional function for implementing branching logic in formulas.
Syntax
if(condition, value_if_true, value_if_false)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| condition | boolean | Yes | The condition to evaluate. |
| value_if_true | any | Yes | The value to return if the condition is true. |
| value_if_false | any | Yes | The value to return if the condition is false. |
Returns
Type: any
Either value_if_true or value_if_false, depending on the result of the condition.
Examples
Set a priority label based on a numeric value:
if([priority] == 1, "Critical", "Normal")
If priority is 1, the result is "Critical". Otherwise, the result is "Normal".
Provide a default value when a field is empty:
if([assigned_to] == "", "Unassigned", [assigned_to])
If assigned_to is an empty string, the result is "Unassigned". Otherwise, the original value is returned.
Nested conditions for multiple outcomes:
if([state] == "closed", "Done", if([state] == "in_progress", "Active", "Pending"))
Returns "Done", "Active", or "Pending" depending on the value of state.
Notes
- For checking whether a value is null specifically, consider using
if_nullwhich handles None, empty strings, empty lists, and empty dictionaries. - Conditions can use comparison operators such as
==,!=,>,<,>=, and<=. - You can nest
ifcalls to handle multiple conditions, but for readability consider breaking complex logic into multiple steps.
Comments
0 comments
Please sign in to leave a comment.