Working with Tableau Context Filters
Updated: Apr 29
By default, all filters you set in Tableau are computed independently. Meaning each filter accesses all rows of data without regard of other filters. However, sometimes you can upgrade some of normal filters to become context filters – in which case the context filter acts as an independent filter and every other filter you set is dependent to that context filter – that is, it can only process data that passes through the context filter.
Such context filters come in handy when you need to;
Improve performance of dashboards – if you set a lot of filters or have a large data source, the queries can sometimes be slow. However, by setting one or two context filters can help improve performance – because every other filter you set processes data that passes through the context filters (less data).
Create a dependent numerical or Top N filter – You can set a context filter to include only the data of interest.
Therefore, whenever you set context filters – these filters will be processed first before any other filter you add in your view. This works according to the Tableau’s order of operations.
(Whereby, context filter comes before any other filter applied at the viz level)
So, how do I create a context filter in Tableau?
I will be using Superstores data to walk you through how to create a context filter in Tableau. In this case, I would like to show the Top 10 States by Sales – for only Technology products.
To do that;
Drag dimension State to the rows shelf.
Drag measure field Sales to columns shelf – aggregate by SUM().
Sort the view in descending by SUM(Sales).
Add filter to show only Top 10 States by Sales
To do that, drag dimension ‘State’ to the filter shelf – on the dialog box under ‘Top’ tab define a filter of Top 10 by SUM of Sales.
Executing this we’ve
Now, let’s add a product category filter and filter our view by ‘Technology’
To do that;
Drag dimension field ‘Category’ to the filter shelf and select ‘Technology’
Executing this we’ve’
Looking carefully at the two views above, you’ll note that the Top 10 States remain the same. Only the metrics and order of States changes. And this is because every filter is evaluated independently and the intersection of the two filters returned.
So, are these really, the Top 10 States by Sales for Technology products?
To answer this question correctly, we’re going to promote ‘Category’ filter to a context filter. By doing so, Tableau will first compute the view based on ‘Technology’ products and then evaluate the Top 10 States based on the context filter.
Adding context filter.
To promote ‘Category’ filter to a context filter.
Under the filters shelf, open the drop-down menu select ‘ Add to Context’
Executing this we’ve;
You will note that in our correct view – two States namely; Indiana & North Carolina have been added. And this is because, Tableau is now evaluating the Top 10 States based on the context filter - that is, Technology products.
Things to note about context filters;
They appear at the top of filters shelf.
They are identified by a grey color on the filters shelf.
They cannot be rearranged on the filters shelf.
I hope this article was helpful to you. To receive more of these Tableau tips and tricks kindly join our mailing list by subscribing below.
Thank you for reading.