Tableau's Context Filter is the first filter to be applied to a worksheet after any other filters. The data that is obtained by the Context filter will be subject to all other filters because it is an independent filter. This will greatly enhance Tableau's efficiency, particularly when there are several filters set to the worksheet and while working with extremely large amounts of data.
Applies to: Tableau Cloud, Tableau Desktop, Tableau Server
Tableau Context Filter is a type of filter that controls the data for the other filters in Tableau. Normal Filters, on the other hand, process all of the data rows from the data source, regardless of the associated filters. Tableau creates a temporary table to process the data from Context Filters, which is why they’re also known as DEPENDENT FILTERS in Tableau. To improve processing performance, the Context Filter is used. In Tableau, it’s a recommended filter condition for creating visualizations from large datasets. Before adding other filters to improve performance, the Tableau Context Filter should be included in the visualization design.
For example, if you want to filter the department based on the employee, you can exclude employees from other departments at that time. This will be beneficial to the database’s small size. If you have data from multinational corporations with more than 20,000 employees, Tableau Context Filter is the right tool to use. To the relevant dimension, you must apply a Context Filter. The Tableau Context Filter can be added and removed from Tableau.
You may create a context filter to:
Force a filter to be carried out first.
Create a dependent numerical or top N filter. You can set a context filter to include only the data of interest, and then set a numerical or a top N filter.
Create Context Filters:
To create a context filter, select Add to Context from the context menu of an existing categorical filter. The context is computed once to generate the view. All other filters are then computed relative to the context. Context filters:
Appear at the top of the Filters shelf.
Are identified by a gray color on the Filters shelf.
Cannot be rearranged on the shelf.
This order means that when we have one or more context filters in a view
any other filters used in that same view are applied only to rows which make it through the context filter. It helps me to think of them as ‘dependant’ on the context filter.
As shown below, the Ship Mode dimension is set to be the context for a view. The Region filter is computed using only the data that passes through Ship Mode.
You can modify a context filter by:
Removing the field from the Filters shelf – If other context filters remain on the shelf, a new context is computed.
Editing the filter – A new context is computed each time you edit a context filter.
Selecting Remove from Context – The filter remains on the shelf as a standard filter. If other context filters remain on the shelf, a new context is computed.
Speed up Context Filters:
To improve performance of context filters, especially on large data sources, follow these general rules.
Using a single context filter that significantly reduces the size of the data set is much better than applying many context filters.
Complete all of your data modeling before creating a context. Changes in the data model, such as converting dimensions to measures, require recomputing the context.
Set the necessary filters for the context and create the context before adding fields to other shelves. Doing this work first makes the queries that are run when you drop fields on other shelves much faster.
If you want to set a context filter on a date you can use a continuous date. However, using date bins like YEAR(date) or context filters on discrete dates are very effective.
Note: Context filters can adversely affect any query performance improvements when you use the Assume Referential Integrity option in the Data menu of the data source. For more information, see Assuming Referential Integrity for Joins.
Example: Create Context Filters
This example walks you through how to create a context filter. First you’ll filter a view to show the top 10 products by sales. Then you’ll create a context filter on product category so you can see the top 10 furniture products.
Use the Sample - Superstore data source to create the initial view shown below. The view shows the sales for all sub-categories, sorted with the highest sale at the top.
2. Now create a Top 10 filter to just show the top selling products. You can create this filter by dragging the Sub-Category field to the Filters shelf. In the Filter dialog box, switch to the Top tab and define a filter that is Top 10 by Sum of Sales. See Filter Data from Your Views(Link opens in a new window) to learn more about defining a Top N filter.
3. When you click OK, you’ll see that the view is filtered to show the top 10 product sub-categories in terms of sales.
4. Now, let’s add another filter to show only furniture products. Drag the Category field to the Filters shelf and select only Furniture. When finished, click OK.
The view is filtered but instead of 10 products, it now shows 3. This is because by default all filters are evaluated separately and the view shows the intersection of the results. So this view shows that three of the top 10 overall products are furniture products.
5. To find out what the top 10 furniture products are we need to make the Category filter a context filter. Right- click the field on the Filters shelf and select Add to Context.
6. The filter is marked as a context filter and the view updates to show the top four furniture products. Why not 10? Because only four of the sub-categories contain furniture. But we now know that the Top 10 filter is being evaluated on the results of that context.
Difference between regular filter and context filter:
Context Filters have a few advantages over Traditional Filters. First, they execute more quickly than Traditional Filters. They are also executed before Traditional Filters and can be executed all at once, which further improves efficiency.
Advantages of context filter:
Context Filter can improve the view performance of the dashboard when using more than one filter. A filter in tableau will be executed over all the rows in the dataset independent of others filters in place.
Disdvantages of context filter:
The context filter isn't oft-times modified by the user – if the filter is modified the info should recompute and rewrite the temporary table, deceleration performance.