Logic Functions

IF function

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.

Examples

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.

Tips when using the IF function

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 function

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.

Examples

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.

Logic Operators

You can use various operators in conjunction with the if() and switch() functions.

 

isEmpty()

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")

 

In (Used for value matching in Select, Link to User and Link to Role Fields)

if("Open" in @Status and "Important" in @Stage, "High Priority", "Low Priority")

 

Equal To

if(@Location = "San Francisco", "Event will be in SF", "Event will be outside of SF")

 

Not Equal To

if(@Location <> "Paris", "Event will be outside of Paris", "Event will be in Paris")

 

Greater Than

if(@Price > 5000, "Expensive", "Cheap")

 

Less Than

if(@Price < 1000, "Cheap", "Normal")

 

Greater Than or Equal To

if(@Task Priority >= 8, "Very Important", "Important")

 

Less Than or Equal To

if(@Task Priority <= 5, "Not Important", "Normal")

 

And/Or

if((@Price > 5000 and @Task Priority >=8) or "Very Important" in @Stage, "Expensive and Important", "Normal")

 

Not

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.

What would you improve in this article?
Powered by:

Type above and the results will be displayed here.