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 aretrue
, otherwise returnsfalse
.- 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. Allows for multiple clauses.
- Examples
-
if (cost > 500) then 'flag' else 'approve' if ( item type in {'shirts', 'jackets', 'sweatshirts', 'sweaters'}) then 'tops' else if item type in {'shorts', 'pants'}) then 'bottoms' else 'all other apparel'
ifnull
-
Returns the first value if it is not
null
, otherwise returns the second value.- Example
-
ifnull (cost, 'unknown')
in
-
Takes a column name and a list of values. It checks each column value against the list of values in the formula, and returns
true
if the column value matches one of the values in the formula.- Example
-
state in { 'texas' , 'california' }
isnull
-
Returns
true
if the value isnull
.- Example
-
isnull (phone)
not
-
Returns
true
if the condition isfalse
, otherwise returnsfalse
.- Examples
-
not (3 > 2) = false not (state = 'texas')
or
-
Returns
true
when either condition istrue
, otherwise returnsfalse
.- 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 also use a sum_if
formula.
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.
-
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.
-
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.
-
Using nested formulas, you can combine these two formulas.
For example:
f1 = ipadcount + galaxycount
-
Now, you can search using the
f1
formula to find out the revenue generated by both products.
Related information