AND() and OR() Functions in Tableau
AND() and OR() functions are logical functions – and just like all other logical calculations these functions test whether a condition is TRUE or FALSE (Boolean function).
AND() is used to perform logical conjunction between two expressions while OR() function performs logical disjunction between two expressions.
In this article I will share case examples showing you how you can apply these two functions in your Tableau projects.
AND() function example
In this example, using Superstores data set, I would like to find out the number of customers spend $1,000+ on ‘Phones’ Subcategory, and purchased 5 items and above.
To answer this question, I will need to perform a logical conjunction between these three metrics as shown below.
Adding this calculation to the rows shelf and COUNTD(Customer Name) to the Text shelf gives 44 customers
(Therefore, in the entire period of 2016 to 2019, only 44 customers spend $1,000+ on ‘Phones’ product Sub-category and purchased 5 items and above.)
You can reveal these customers by right-clicking on the metric >> View Data…
Under Full Data, you can see the full Customers list.
OR() function example
In this example, using same Superstores data set, I will use OR function to combine the ‘East’ and ‘West’ region’s as ‘Coastal Region’ while retaining the rest of Regions’ names. Basically, this can be achieved by grouping data, but in this case I will use OR() function to achieve the same results.
Using the formula below.
(This calculation basically will assign the name ‘Coastal Region’ in every row where region is either ‘East’ or ‘West’ while retaining the rest of regions’ names)
Adding this calculation to the rows shelf and Region to the text shelf clearly tells you that the two regions’ have been combined as per the problem above.
There are many more ways you can apply AND() and OR() functions in Tableau. I believe these two examples will help you utilize Tableau better in your dashboarding assignments.
To receive more of the Tableau tips and tricks, kindly join our mailing list by subscribing below.
Thank you for reading.