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