Context filters are applied before any other filters in the worksheet other than extract and data source filters. A context filter is an independent filter that can create a separate dataset out of the original data set and compute the selections made in the worksheet. Any other filters that you define are dependent filters as they process the data that passes through the context filter. All other filters used in the worksheet works based on the selection of context filters.
Context filters are used mainly for
1. Improving the performance: If you set 1 or more filters to context, then you are putting a limit on the amount of data, that the rest of the filters would process, which in turn increases the performance
2. Obtain Selective Measures: If you wanted to select the top N (Ex. Top 5) filter for a particular criteria on a specific data set, context filters may be used
Context filters can be explained in detail with the help of the below example:
Show top 5 customers by sales based on the region.
Firstly, display customer data by sales irrespective of region
Drag the Customer Names field into the Filters shelf, click on the Top tab and select ‘By field’ as shown below:
When we select the different regions as filters, tableau applies the region filter on top of the top 5 customers instead of showing the Top 5 customers within the required region as screenshot below:
Hence, the trick is to apply Region in the Filters tab to the context level. So that the top 5 customers are being displayed at the region level.
Context filters are highlighted with a gray background.
Now, after applying context filters, the top 5 customers of a specific region are displayed correctly.
Removing Context Filter:
Any context filter can be changed back to a normal filter by right-clicking on the dimension in the filter's shelf and selecting the “Remove from Context” option. The color of the dimension box will also change back to blue color as there are no context filters applied to it.