By default, Filters in Tableau calculate independently. It means each filter will access all the records present in your data source individually. It might be OK if your data source is small, but it will be a bad practice for a large data source.
For example, we want to analyze the Top 10 products in each city present in the United States.
- The first filter will find the highest performing products within the world.
- The second filter to display the cities within the United States.
Here, both will access the data source independently, and I must say it’s repeated work. In such a case, we can use the Context Filters in Tableau.
From the above example, if we make the second filter as the Tableau Context filter, then the first filter will search for the data based on the second filter. It means, within the United States, and no need to search for the whole world. Let me show you one example so that you can understand the concept of context filters in Tableau.
Before getting into this Tableau context filter example, Please refer Filters to understand the basic filtering techniques. For this Tableau Context filters demo, we are going to use the data source that we created in our previous article. Please visit Data Labels in Tableau Reports article to understand the Tableau Data Source.
I suggest you remember this report. It can help you to understand the list of categories, subcategories, and its respective Sales Amount we had in our data source
Create Context Filters in Tableau
In this example, we will show you how to create Context Filters in Tableau. Our scenario is to find the Top 10 product Subcategories present in the Accessories, and Clothing (Product Category).
First, Drag and Drop the English Product Subcategory from Product Hierarchy present in the Dimension Region to Rows Shelf, and Sales Amount Measures region to Columns Shelf. By default, tableau will generate the Bar Chart.
Here, we are going to add a filter condition on the English Product Name. First, Please click on the down arrow beside the Product Subcategory Name present in the Row Shelf will open the menu. Here, you have to select the Filter.. option.
Once you select the Filter.. option, a new window is opened to create a filter. Please navigate yourself to the Top tab. From the below screenshot, you can observe that we are selecting the By filed section.
Next, we selected the Top 10 records, Sales Amount as the Measure, and Sum as the Aggregate function. I suggest you refer, Top Filters in Tableau article to understand the properties.
By clicking the OK button, we created our first filter that will find the top 10 subcategories based on the Sum of Sales Amount.
Next, we are going to add filter condition on Product Categories. To do so, please drag and drop the Product Category from Dimension Region to Filters Shelf.
Once you drop the Product Name to Filters Shelf, a new window called Filter will open. For the demonstration purpose, Within the General, please check the Accessories and Clothing. I suggest you to refer Tableau Filters on Dimensions article to understand the properties.
From the below screenshot, you can see that the report is displaying seven subcategories from the Accessories and Clothing category. It means the first Tableau applied the First filter and extracted the top 10 subcategories.
Next, it applied the second filter and displaying the subcategories from in the Accessories and Clothing. We all know that it has three records that represent the Bikes Category.
Now let us change the English Product category name filter as the Tableau Context Filter. To do so, go to the Filter Shelf and Click on the down arrow beside the category. It will open the menu, and from that menu, please select the Add to Context option.
Once you select the Add to Context option, the English Product category name filter will convert to the Tableau context filter. As per the Tableau order of execution, the Context filter will be executed first, followed by Filters on Dimension, and then Filters on Measures.
From the below screenshot you can see that it is displaying the top 10 subcategories present in the Accessories, and Clothing
Remove Context Filters in Tableau
To remove Tableau context filters, Go to the Filter Shelf. Next, click on the down arrow beside the context filter that you want to remove. It will open the menu, and from that menu, please select the Remove from Context option.
That removes the context filter in Tableau