Understanding the order of operations in Tableau is crucial for ensuring that data is processed and visualised accurately. This blog will demonstrate the importance of this through the use of context filters.
The figure below describes the order in which actions happen within Tableau. Crucially, for the understanding of this blog, it is important to note that top N filtering sits above dimension and measure filters, yet below context filters.
Image Source: https://help.tableau.com/current/pro/desktop/en-us/order_of_operations.htm
Let's imagine that we are working with the superstore dataset from Tableau and want to see the top 10 customers in terms of sales. To do this we can create a simple bar chart with a y-axis of customer names and an x-axis of sales. We could then use a top N filter to select only the top 10 customers. The result can be seen below.
Now, imagine we wanted to see the top 10 customers, but only from stores located in the west. It would be easy to assume that to do this we could simply add an extra filter to select our desired region. The result of this is shown below.
As you can see only 6 customers are now in our chart. This does not answer our question of “who are the top 10 customers, in terms of sales, in the west?”.
What has happened here is that Tableau’s order of operations have come into play. Our customer filter is a top N filter, while our region filter is purely dimensional. This means the region filter is applied only after the top N filter has completed its action. As a result, the graph we’re seeing displays the top 10 customers overall, and then filters this list by region. We are, therefore, seeing missing values because some of the company’s top 10 customers have never shopped in the West.
To change this, we need to use a filter that has priority over top N filters in Tableau’s order of operations. We can do this by turning our measure filter into a context filter. This can be right clicking on the filter we want to change and selecting add to context.
Our new table looks like this:
Much better! We have now visualised who the top 10 customers are within the west region.