Tableau Training and Certification
- 23k Enrolled Learners
- Live Class
Creating Filters is a very important aspect of Tableau. In this article, we will understand Context Filters in Tableau in the following order:
Generally, all the filters that you set in Tableau are independently computed. Basically what it means is that each filter accesses all rows in your data source without regard to other filters. A context filter is like an independent filter. Any other filter that is set is termed as a dependent filter due to the fact that they only process the data that passes through the context filter.
Now, you can deploy a context filter to achieve either of the following;
Better Performance: If there are a lot of filters set or the data source is rather large, the queries tend to be slower. In such a scenario, one can set context filters to improve performance.
Top N Filter: One also can set a context filter to include only their data of interest, followed by setting a numerical or a top N filter.
For instance, if you’re in charge of food products for a really large grocery chain. Your task is to find the top 10 snack bars by profitability for all stores. Obviously, the data is enormous. Here, you can set a context filter to include only snack bars and create a top 10 filter by profit as a dependent filter. This would process only the data that passes through the context filter.
To build a context filter follow the given steps below;
As shown in the image above, the Ship Mode dimension is set to be the context for a view and the Region filter is only computed using the data that passes through Ship Mode.
You can make modifications to a context filter by doing one of the following things;
Removing the field from the Filters shelf (A new context is computed if other context filters remain on the shelf)
Editing the filter (A new context is computed each time you edit a context filter)
To improve the performance of context filters, and hence, increase the efficiency of Tableau, you could follow these guidelines;
Deploying a single context filter that significantly reduces the size of the data set is a way better idea than applying many filters. As a matter of fact, if a filter does not reduce the size of the data set by one-tenth or more, it is actually worse to add it to the context. It costs the performance of computing the context.
It’s reckoned to finish all of your data modelings before creating a context. Alterations in the data model, such as converting dimensions to measures, require recomputing of the context.
Set the required filters for the context. Also, create the context before adding fields to other shelves. These prerequisites make the queries that are run much faster when you drop fields on other shelves.
Using date bins like YEAR(date) or context filters on discrete dates are more effective than using continuous dates.
If your data set is heavily indexed, context filters may not provide the performance you’re looking for and may also, actually cause slower query performance.
This example is intended to take you through the procedure of building a context filter.
First, you’ll filter a view to show the top 10 products by sales. Next, 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. The view shows the sales for all Sub-Categories, sorted in descending order.
Now build a Top 10 filter to only show the top-selling products. You can do so by dragging the Sub-Category field to the Filters shelf. In the dialog box that appears, switch to the Top tab and define a filter that is Top 10 by Sum of Sales.
When you click on the OK button, you shall see that the view is filtered to show the top 10 product Sub-Categories in terms of sales before you.
Moving on, let’s try and add another filter to show only furniture products. Now drag the Category field to the Filters shelf and select the only Furniture. When done, click on the OK button.The view is filtered but instead of 10 products, it now shows only 3. This is due to the fact that by default all filters are evaluated separately and the view is designed to show the intersection of the results. So on the screen you’ll see that three of the top 10 overall products are furniture products.
If you wish to master Tableau, Edureka has a curated course on Tableau Training & Certification which covers various concepts of data visualization in-depth, including conditional formatting, scripting, linking charts, dashboard integration, Tableau integration with R and more. It comes with 24*7 support to guide you throughout your learning period. New batches are starting soon.
Got a question for us? Please mention it in the comments section of “Context Filters in Tableau” and we will get back to you at the earliest.