Context Filters in Tableau

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.

Context Filters in Tableau 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; I must say 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, 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 will use the data source we created in our previous article.

Before getting into this example, Please refer to 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 in the Accessories and Clothing (Product Category).

First, Drag and Drop the English Product Subcategory from the Product Hierarchy in the Dimension Region to Rows Shelf and Sales Amount Measures region to Columns Shelf. By default, the desktop will generate the Bar Chart.

Tableau Context Filters in Bar Chart 2

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.

Context Filters in Tableau 3

Once you select the option, a new Tableau Filter window will open to create the expression for context. 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. Again, I suggest you refer to the Top 10 products article to understand the properties.

Tableau Context Filters By Field 4

By clicking the OK button, we created our first Tableau context filter to 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 refer to Apply on Dimensions article to understand the properties.

Context Filters in Tableau 6

The screenshot below shows that the report displays 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 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 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 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 you want to remove. It will open the menu, and from that menu, please select the Remove from Context option.

Remove Tableau Context Filters

It will remove them.

Report without Tableau Context Filters