top of page
Writer's pictureBernard Kilonzo

AND() and OR() Functions in Tableau

Updated: 5 days ago

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.

AND function calculation in Tableau

Adding this calculation to the rows shelf and COUNTD(Customer Name) to the Text shelf gives 44 customers

table view

(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…

viewing data in tableau

Under Full Data, you can see the full Customers list.

viewing data in tableau
Viewing data in Tableau

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.

OR function calculation in Tableau

(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.

data table

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.

Blog.png
bottom of page