Ever wondered what the following "Add to Context" option in Tableau is?
How is this context filter different from a normal filter?
How does this affect the visualizations that I am building?
I will try to answer these questions as clear as possible in the sections below.
What is the difference between a filter and a context filter?
A normal filter works independently from the other filters and always looks at the entire dataset.
The image below shows this filtering process:
The context filter is higher in rank, so he goes first when it comes to filtering. This means he filters the entire dataset and gives the filtered result to the normal filter guys.
These normal filters can now work with the result dataset of the context filter.
The image below shows this clearly:
I did not come up with this order that a context filter is executed before a normal filter by myself. This is the standard order of operations in Tableau.
The gif below shows the entire order of operations:
Theory is nice, but how does it work in practice?
Well, let's say that I am interested in my top 10 customers by their sum of sales. Not only the global top 10 but for each segment separately.
We start off by showing the overall top 10 customers.
This seems to work fine. Now try to add a quick filter showing your different segments:
When we try our quick filter, we see the data changing but we no longer have a top 10:
Tableau looks at our top 10 and filters the customers who belong to the Home Office segment.
This is not the result we want. We would like to see 10 customers when we select the Home Office, meaning that Tableau needs to calculate something after we selected a filter value.
Right click in the filter shelf on Segment and select "Add to context".
Now each filter option should always show 10 customer names!
This is because our Segment context filter is executed before a top 10 is calculated.
Are there additional benefits to a context filter?
Well yes, they also improve the performance in Tableau!
We are not going to dive into the performance part in this blog, in case you are interested please check the Tableau documentation here.
Join the Data Jam
92% of companies fail to scale their analytics, which likely includes you. We have studied the patterns in hundreds of client engagements and cracked the code for a modern data stack that guarantees success.
We'll uncover this in the most original webinar you've attended this year.