Formula operators

Learn how to use formula operators for conditional calculations.

Formula operators allow you to apply if/then/else conditions in your formulas. You can leverage operators in your formulas to have them return true, false, or a predetermined value.

Formula operators

The operators include:

and

Returns true when both conditions are true, otherwise returns false.

Examples
(1 = 1) and (3 > 2) = true
lastname = 'smith' and state ='texas'
Not available for row-level security (RLS) formulas.
if…​then…​else

Conditional operator.

Examples
if (3 > 2) then 'bigger' else 'not bigger'
if (cost > 500) then 'flag' else 'approve'
ifnull

Returns the first value if it is not null, otherwise returns the second value.

Example
ifnull (cost, 'unknown')
isnull

Returns true if the value is null.

Example
isnull (phone)
not

Returns true if the condition is false, otherwise returns false.

Examples
not (3 > 2) = false
not (state = 'texas')
or

Returns true when either condition is true, otherwise returns false.

Examples
(1 = 5) or (3 > 2) = true
state = 'california' or state ='oregon'

Calculate the conditional sum

Calculating the conditional sum is useful when you want to see, for example, the total revenue for a product by region.

Conditional sum formulas follow this syntax: if (some condition) then (measure) else 0. You can use this syntax to limit your search in cases when you don’t want to add a column filter. For example: if ( product = shoes ) then revenue else 0

The following example shows you how to figure out the number of customers who bought both products, in this case an iPad and Galaxy tablet. You can then find out the revenue generated by both products.

  1. Create the following formula in the Formula Builder:

    ipadcount = sum ( if ( product = 'ipad' ) then 1 else 0 ) > 0

    This formula will provide you with the number of iPads that were bought.

  2. You can then create another formula that looks like this:

    galaxycount = sum ( if ( product = 'galaxy' then 1 else 0 ) > 0

    And this formula will provide you with the number of Galaxy tablets that were bought.

  3. Using nested formulas, you can combine these two formulas.

    For example: f1 = ipadcount + galaxycount

  4. Now, you can search using the f1 formula to find out the revenue generated by both products.


Related information