If
The If function returns Value 1 for every row where the first condition is met. If more than one condition is supplied, the second condition is evaluated and returns Value 2 for every row where the second condition is met. If all conditions are False, then the Else value is applied for every row that does not belong to the preceding conditions.
Syntax
If(condition 1, value 1, [condition 2], [value 2],..., [else])
Function arguments:
- condition 1 (required) Logical condition that returns a result that is either True or False.
- value 1 (required) The value to be returned if its preceding condition is True.
- condition 2+, value 2+ (optional) Several If/Then pairs can be listed in a single function. Every supplied condition must have a corresponding value.
- else (optional) The value to be returned if no conditionals evaluate to True.
If an Else argument is not specified, a Null result is returned by default when no conditions are met.
You can use operators in conditions.
Examples
If([size] < 3, "small", [size] < 6, "medium", "large")
Groups records into categories based on size. Returns small if [size] less than 3, medium if [size] is less than 6, and large if [size] is greater than or equal to 6.
If([revenue] - [cost] > 0, "profit", "loss")
Categorizes a record as a profit or a loss based on revenue and cost. If [revenue] - [cost] is greater than 0, returns profit. Otherwise, returns loss.
If([Product Family] = "Cameras & Camcorders" OR [Product Family] = "Camera Accessories", "Photography")
Categorizes records in the product family with an overarching product type using the "OR" operator. If [Product Family] is either Cameras & Camcorders or Camera Accessories, returns Photography.
If(IsNull([Text]), 1, 0)
Checks if the column [Text] is Null. Returns 1 if it is null, and 0 if it is not.
If([Number] > 0, If(Mod([Number], 2) = 0, "Even", "Odd"), "Negative")
Checks if a number is positive from the column [Number]. If it is positive, it checks if the number is even or odd. Otherwise, it returns Negative. This is a nested If statement, meaning the If statement in the second argument will only ever be evaluated for the outcome "Even" or "Odd" if the first condition of the outer If statement - [Number] > 0 - is true.
- For a row where
[Number]has a value 7, this returnsOdd. - For a row where
[Number]has a value 2, this returnsEven. - For a row where
[Number]has a value -1, this returnsNegative.
Updated about 7 hours ago
