Context Filters in Tableau

By default, Context Filters in Tableau calculate independently. It means each one 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.

Context Filters in Tableau example, we want to analyze the Top 10 products in each city present in the United States.

  • The first one will find the highest performing products within the world.
  • The second is 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 or set a Context Filters in Tableau.

From the above example, if we set the second one as the Tableau Context filter, then the first will search for the data based on the second. 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.

For this Tableau Context filters demo, we are going to use the data source that we created in our previous article. Before getting into this Tableau context filter example, Please refer Filters to understand the basic techniques. Also, please visit Data Labels in Reports article to understand the Tableau Data Source.

I suggest you remember this Tableau Context Filters report. It can help you to understand the list of categories, subcategories, and their respective Sales Amount we had in our data source

Sample Report

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.

Context Filters in Bar Chart 2

Here, we are going to add a 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 below shown option.

Context Filters in Tableau 3

Once you select the option, a new window is opened to create the expression. 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 10 products article to understand the properties.

Context Filters By Field 4

By clicking the OK button, we created our first context filter in tableau that will find the top 10 subcategories based on the Sum of 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.

Context Filters in Tableau 5

Once you drop the Product Name to the Shelf, a new window will open for the configuration. For the demonstration purpose, Within the General, please check the Accessories and Clothing. I suggest you to refer Apply on Dimensions article to understand the properties.

Context Filters in Tableau 6

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 category context filter and extracted the top 10 subcategories.

Next, it applied the second one and displaying the subcategories from in the Accessories and Clothing. We all know that it has three records that represent the Bikes Category.

Context Filters in Tableau 7

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.

Context Filters in Tableau 8

Once you select the option, the English Product category name expression will convert to the Tableau context filter. As per the order of execution, the Context filter will be executed first, followed by the Dimension, and then on Measures.

From the below screenshot you can see that it is displaying the top 10 subcategories present in the Accessories, and Clothing

Top 10 Categories

Remove Filters

To remove Tableau context filters, Go to the shown 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