Skip to main content

IF

Returns one value if a logical expression is TRUE and another if it is FALSE.

Syntax

IF(<condition>, <then>, <else>)
ParameterTypeDescription
conditionBooleanAn expression that returns logical value, i.e. TRUE or FALSE.
thenanyThe value the function returns if condition is TRUE.
elseanyThe value the function returns if condition is FALSE.

Return values

Depends on input arguments.

Examples

IF(orders.country == "US", "United States", "Other")
IF(products.qty > 0, "in stock", "out of stock")
IF(
AND(customers.orders > 10, DATEDIFF(customers.last_order_at, NOW(), DAY) < 10),
"Loyal",
IF(
DATEDIFF(customers.last_order_at, NOW(), DAY) > 50),
"Dormant",
"New"
)
)