When working in Tableau, sometimes filters don't behave as expected. One filter can to override another, leading to an incorrect view of the data. This common challenge is often solved by a powerful yet simple feature: Add to Context.
What is a Context Filter?
In Tableau filters are typically independent, meaning they all apply to the data source and don't impact each other's filtering process. This is where a context filter comes in. A context filter is an independent filter that's executed before all other filters. When you "add a filter to context," Tableau creates a temporary table that includes only the data that passes through the context filter. All other filters on the sheet then operate on this temporary table, not the full data source.
Why use a Context Filter?
The main reason to use a context filter is to control the filter order of operations. The typical example is a Top N filter. If you want to show the top 10 products by sales. You create a filter to rank products by sales and only show the top 10. Now you want to show the top 10 products within a specific region. If you just add a "Region" filter, it won't work as you expect. The "Top 10" filter is still working on the whole dataset, therefore it's showing the top 10 products globally, and then the region filter is just showing you if any of those top 10 happen to be in your selected region.
This is where you would add the Region filter to context. Now, Tableau first created a table with only the data for the selected region. Then, it calculates the top 10 products from that temporary table.
How to use the "Add to Context" Function
- Drag a Dimension into the Filters shelf
- Right-click on the filter and select Add to Context
The filter will turn grey on the shelf, visually indicating that it is a context filter. If you have multiple filters, the context filter will appear at the top of the shelf, above all other filters.