How to Use Tableau Context Filters (Complete Guide with Examples)

In Tableau, filters play a very important role in analyzing and visualizing data. When working with dashboards, we often apply multiple filters to get specific results.

However, the output may not be as expected because Tableau processes filters in a specific order. This is where context filters become very useful.

A context filter in Tableau is a special type of filter that helps control how other filters are applied. It allows you to create a data subset first and then apply additional filters on top of it.

This concept is particularly important when working with large datasets, using Top N filters, or building complex dashboards.

Recently, I analyzed sales data across various product categories using a bar chart. In this, I implemented a filter in the subcategory to show the top 5 records with the highest sales.

In this, I also used the Category filter to exclude subcategory sales from their parent category. For example, I applied a Top N filter to show the Top 5 Sub-Categories by Sales.

Then I used another filter on the Category (e.g., removing Furniture), and the chart showed only 3 Subcategories instead of 5.

The records were displayed like this because Tableau first calculates the top 5 records, then applies the Category filter after the calculation. That means it is removing the records from the filtered top records.

In this case, I needed a solution that allows me to apply a Category filter and calculate the top N records. In Tableau, it was possible to use the Context filters.

In this Tableau tutorial, I will explain context filters in Tableau and how to use them in Tableau worksheets.

What is a Context Filter in Tableau?

By default, Tableau applies all filters independently. This means each filter works on the entire dataset without considering other filters.

But when we have multiple filters, we want one to act as the “primary filter,” with the others applying only within the subset defined by the primary filter.

However, a context filter changes this behavior. It creates a temporary data subset, and all other filters are applied only to that subset.

In simple words:

  • Context filter = Primary filter
  • Other filters = Dependent filters

This means:

  • First, the context filter is applied
  • Then, other filters are applied to the filtered data

This helps improve performance and achieve accurate results.

To define a filter as a primary filter, set it as a context filter. It creates a temporary data subset based on the selected filter. With this, all other filters are then applied only within the subset of the context filter.

Why Do We Need Context Filters?

Sometimes, when we apply multiple filters, Tableau gives incorrect or unexpected results. This happens because filters are processed independently and then combined.

For example:

  • You apply the Top 10 products filter
  • Then apply the Category filter

You may get fewer than 10 results because Tableau first finds the top 10 from all data and then applies the category filter.

To fix this, we use a context filter. A context filter forces Tableau to apply one filter first before others.

Key Features of Context Filters

  • Works as a primary filter
  • Creates a temporary dataset
  • Other filters depend on it
  • Improves performance in large data
  • Useful for Top N and conditional filters

When to Use Context Filters

Use context filters in these situations:

  • When working with large datasets
  • When using Top N filters
  • When filters depend on each other
  • When performance optimization is needed

Create Tableau Context Filters

In this example, I will create a bar chart using the Tableau Superstore dataset to show the top 5 subcategories with the highest sales.

Now connect Tableau to the Superstore dataset and follow the steps below.

Add the Sales to Columns and Sub-Category to the Rows.

    Tableau Context Filters

    To show the top 5 records in subcategory sales, click on the Sub-Category in the Rows and select Filters. Then, in the Filter window, select Top -> By field -> Top 5 -> Sales, and click OK.

      Create a Context Filter in Tableau

      Now, the records will be filtered to display the top 5 records with the highest sales.

      For the context filter, add the Category to the Filters. Now, right-click on it in the Filters section and select Add to Context.

      As a result, the Category will appear in grey in the Filters section.

        Add to Context filter in Tableau

        Now, the subcategory will show the top 5 results in the context of the Category filter. Here, I have shown the difference in how records are filtered with and without a context filter.

        With context filter:

        Filter records with context filter in Tableau

        Without Context filter:

        Context filters in top n results in Tableau

        This way, we can create and use context filters in Tableau by following the steps above.

        Advantages of Context Filters

        • Improves Performance
          • When working with large datasets, context filters reduce the data size first. This makes queries faster
        • Helps in Top N Filters
          • Context filters allow the correct calculation of Top N values.
        • Better Data Control
          • You can control how filters interact with each other.
        • Useful in Complex Dashboards
          • Helps manage multiple filters effectively.

        Disadvantages of Context Filters

        Even though context filters are powerful, they have some limitations:

        • Performance Issue (if used incorrectly)
          • If you use too many context filters, It may slow down performance
        • Re-computation Required
          • Whenever you change a context filter, Tableau recalculates data
        • Not Always Needed
          • Using context filters unnecessarily can make dashboards complex.

        Context Filter vs Normal Filter

        FeatureNormal FilterContext Filter
        ProcessingIndependentFirst applied
        Data ScopeFull datasetSubset
        DependencyNoYes
        PerformanceNormalFaster (large data)

        Frequently Asked Questions

        Q1: What is a context filter in Tableau?

        A filter that is applied first and controls other filters

        Q2: Why use context filters?

        To improve performance and correct filter results

        Q3: How to identify a context filter?

        It appears in gray color

        Q4: Can we use multiple context filters?

        Yes, but use it carefully

        Q5: Does context filter improve performance?

        Yes, especially for large datasets

        Conclusion

        Context filters in Tableau are a powerful feature that helps you control how data is filtered and processed. They allow you to create a subset of data first, then apply additional filters on top of it. This is especially useful when working with large datasets, Top N filters, or complex dashboards.

        Understanding context filters is important for every Tableau developer because it improves both performance and accuracy. If used correctly, context filters can make your dashboards faster, cleaner, and more meaningful.

        You can follow the same steps to use any filter in Tableau as a context filter and create a filtering hierarchy to ensure that context filter data is processed first.

        You may also like to read:

        Agentforce in Salesforce

        DOWNLOAD FREE AGENTFORCE EBOOK

        Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

        Salesforce flows complete guide

        FREE SALESFORCE FLOW EBOOK

        Learn how to work with flows in Salesforce with 5 different real time examples.