By default, Filters in Tableau are calculated independently. It means, each filter will access all the records present in your data source independently. It might be OK if your data source is small but it will be bad practice for the large data source. For example, we want to analyze the Top 10 products in each city present in United States.
- First filter will find the highest performing products within the world.
- Second filter to display the cities within the United States.
Here, both will access the data source independently, and I must say it’s kind of 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 Context filter then 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.
Before getting into this, Please refer Tableau Filters to understand the basic filtering techniques. For this 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 Data Source.
I suggest you to remember this report. This can help you to understand the list of categories, subcategories, and its respective Sales Amount we actually had in our data source
Creating Context Filters in Tableau
In this example we will show you, How 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 as shown below.
Here, we are going to add filter condition on English Product Name. First, Please click on the down arrow beside the Product Subcategory Name present in the Row Shelf will open the menu as shown below. Here, you have to select the Filter.. option.
Once you select the Filter.. option, a new window is opened to create filter. Please navigate yourself to 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 to refer, Top Filters in Tableau article to understand the properties.
By clicking 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 as shown below.
Once you drop the Product Name to Filters Shelf, a new window called Filter will be opened as shown below. 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 7 subcategories from the Accessories, and Clothing category. It means, first Tableau applied the First filter and extracted top 10 subcategories. Next, it applied the second filter and displaying the subcategories from in the Accessories, and Clothing. As we all know that it has 3 records that represent the Bikes Category.
Now let us change the English Product category name filter as the 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 as we shown below.
Once you select the Add to Context option, English Product category name filter will be converted to the context filter. As per the Tableau order of execution, 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 top 10 subcategories present in the Accessories, and Clothing
Remove Context Filters in Tableau
Go to the Filter Shelf and 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 as we shown below.
That will remove the context filter in Tableau
Thank You for Visiting Our Blog