Logic Functions

IF function

if(<Boolean Expression>, <Value if True>, <Value if 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.

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.

 

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.