if(<Condition>, <Result if condition is true>, <Result if condition is false>)
The IF function is used to evaluate whether a Boolean expression is true or false, and return different values based on the expression result.
if(1 = 1, "Values are the same", "Values are different")
In its simplest form, you can use the IF function to evaluate simple and complex expressions and print values based on the expression result.
For example, because "1 = 1" equates to the Boolean value true, the "Values are the same" text will be printed as the Field value.
In the IF function, the result of both possible conditions should be of the same type.
Same type -> if(<Condition>, "Text result", "Another text result")
Different type -> if(<Condition>, "Text result", 55)
If both possible results aren't of the same type, a warning will be displayed. Sometimes you can't know beforehand, for example when referencing a Field in the result.
If a Field value is empty, it will default to a Text value, even if the Field is of a different type. There are some functions you can use as a workaround.
Instead of the IF function, you can use the dateIf, numberIf, textIf, boolIf functions when you want to have the results to default to a specific type.
dateIf(<Condition>, @DateField1, @DateField2)
Another option is to make sure the possible results default to the desired types by using the asDate, asNumber, asText, asBool functions.
if(<Condition>, asDate(@DateField1), asDate(@DateField2))
switch(<Select Field>).case(<Select Item>, <Value>).default(<Value>) : <Value>
switch().case(<Condition>, <Value>).default(<Value>) : <Value>
The switch function goes through a list of Select Items or conditions and should there be a match, returns the corresponding value. If none of the Select Items or Conditions match, the default value is returned.
The first variation of the switch function takes a Select Field as a parameter. Multiple case statements can be appended to the switch function. Please note that Select Items must match your Select Field values.
switch(@ProductCategory).case("Category A", @BaseTax + 5).case("Category B", @BaseTax + 10).default(@BaseTax)
The second variation of the switch function works on multiple conditions rather than a Select Field. Multiple case statements can be appended to the switch function.
switch().case(@Price > 1000, "Expensive").case(@Price > 500, "OK").case(@Price > 0, "Inexpensive").default("Price Not Available")
If the @Price value is equal to 50, the cascading switch statement result would be "Inexpensive". If the @Price value is equal to 1400, the statement result would be "Expensive".
Note: The default returned value is required in the Switch function.
You can use various operators in conjunction with the if() and switch() functions.
The isEmpty function is used to return whether a particular Field value is empty or not.
if (isEmpty(@Status), "No list item selected yet", "List items selected")
if("Open" in @Status and "Important" in @Stage, "High Priority", "Low Priority")
if(@Location = "San Francisco", "Event will be in SF", "Event will be outside of SF")
if(@Location <> "Paris", "Event will be outside of Paris", "Event will be in Paris")
if(@Price > 5000, "Expensive", "Cheap")
if(@Price < 1000, "Cheap", "Normal")
if(@Task Priority >= 8, "Very Important", "Important")
if(@Task Priority <= 5, "Not Important", "Normal")
if((@Price > 5000 and @Task Priority >=8) or "Very Important" in @Stage, "Expensive and Important", "Normal")
if(Not true, false, true) => true
Note: Operators can also be used outside of the if() function.
Learn more about how you can get started using the Formula Field.
Type above and the results will be displayed here.