if
Returns one value if a logical expression is TRUE and another if it is FALSE.
Syntax
if(<condition>, <then>, <else>)
| Parameter | Type | Description |
|---|---|---|
| condition | Boolean | An expression that returns logical value, i.e. TRUE or FALSE. |
| then | any | The value the function returns if condition is TRUE. |
| else | any | The value the function returns if condition is FALSE. |
Return values
Depends on input arguments.
Usage
Returns 'United States' if country is 'US', otherwise 'Other'.
if(orders.country == "US", "United States", "Other")
Returns 'in stock' if quantity is greater than 0, otherwise 'out of stock'.
if(products.qty > 0, "in stock", "out of stock")
Returns one value if condition is true, another if false.
if(
and(customers.orders > 10, date_diff(customers.last_order_at, now(), DAY) < 10),
"Loyal",
if(
date_diff(customers.last_order_at, now(), DAY) > 50),
"Dormant",
"New"
)
)