Context Filters in Tableau
Tableau’s default setting for all filters is independent computation. Consequently, each filter examines every row in your data source without taking into account the effects of previous filters. One or more categorical filters can be configured as context filters for the view, though.
Define Context Filters
Contextual filters are separate filters because they only handle information that has already passed through the context filter, all additional filters you employ are referred to as dependent filters. In this blog, we are going to explain how to implement context filters in Tableau.
A context filter could be made to force the application of a filter and make a top N or dependent numerical filter. You can first establish a context filter to only contain the relevant data, and then you may apply a top N or numerical filter.
Consider the scenario where you are in charge of a huge grocery chain’s breakfast offerings. The top 10 breakfast items by profitability across all stores are what you need to find. You can establish a context filter to only include breakfast products if the data source is quite vast. Then, as a dependent filter, you may make a top 10 filter by the profit that would only process data that has already passed through the context filter.
Enroll for the Best Tableau Training in Chennai at SLA to become a master in using context filters.
Create Context Filters
Choose from the context menu and add to the context of an existing categorical filter to create a context filter. To create the view, the context is computed once. Then, all additional filters are calculated in relation to the context. Background checks:
- Show up on the Filters shelf’s top.
- Distinguished on the Filters shelf by a gray color.
- It is fixed to the shelf and can’t be shifted.
The context for a view is configured to be the Ship Mode dimension, as can be seen below. Only the information that makes it via Ship Mode is used to compute the Region filter.
A context filter can be changed by :
- When a field is removed from the Filters shelf, a new context is computed if any other context filters are still present.
- Editing the filter: Every time you make changes to a context filter, a new context is computed.
- By choosing Remove from Context, the filter is kept as a regular filter on the shelf. A new context is computed if other context filters are still in use.
Speeding up Context Filters
Follow these general guidelines to enhance the performance of context filters, especially on huge data sources.
It is far preferable to use a single context filter that drastically minimizes the size of the data set as opposed to using numerous context filters.
Create a context only after you have finished all of your data modelings. Recalculating the context is necessary when the data model is altered, for as when dimensions are changed to measures.
Before adding fields to other shelves, set the context’s necessary filters and establish the context. The queries that are executed when fields are dropped on other shelves are substantially faster when this job is completed first.
You can use a continuous date to set a context filter on a date. On discrete dates, however, utilizing date bins like YEAR(date) or context filters is particularly useful.
Note: When you utilize the Assume Referential Integrity option in the Data menu of the data source, context filters may negatively affect any increases in query performance. See Assuming Referential Integrity for Joins for further details.
Review our Tableau Interview Questions to refresh your memory and enhance your self-assurance to ace the technical rounds with ease.
Example for Creating Context Filters
You may learn how to create a context filter by following the example. You’ll first filter a view to display the top 10 products according to sales. The top 10 furniture products will then be displayed thanks to the context filter you created based on the product category.
Step 1: The basic view displayed below should be created using the Sample: Superstore data source. The view lists all subcategory sales in ascending order by highest sale.
Step 2: Build a Top 10 filter now to display only the top-selling items. Drag the Sub-Category field to the Filters shelf to create the filter. Change to the Top tab in the Filter dialogue box and create a Top 10 by Sum of Sales filter. For additional information on how to define a Top N filter, see Filter Data from Your Views.
Step 3: The view will be filtered to display the top 10 product subcategories based on sales after you click OK.
Step 4: Let’s now add a new filter to only display furniture-related products. Only choose Furniture by dragging the Category field to the Filters shelf. After you’re done, click OK. The view has been filtered, but now only 3 products are visible rather than 10. This is because by default each filter is assessed independently, and the view displays the intersection of the results. As a result, this view reveals that three of the top 10 products overall are furniture items.
Step 5: We must convert the Category filter into a context filter to determine the top 10 furniture items. On the Filters shelf, right-click the field and choose to Add to Context.
Step 6: The view is updated to display the top four furniture items and the filter is designated as a context filter. We are aware that the Top 10 filter is assessed based on the outcomes of that context.
To prepare for in-demand data analytics careers with an understanding of the skills required by the industry, read our article on Tableau Jobs..
Softlogic offers a tailored Tableau Course that covers various visual data concepts in depth, such as dashboard integration, formulas, and functions, typescript, integrating charts, Tableau integration with R, and more.
Gain expertise with context filters through our Tableau Course in Chennai with IBM Certification at SLA.