While working with the Sample Superstore data set (yet again!), it was required to show the sales for the top 10 most profitable customers in the Small Business segment. I dragged ‘Customer Name’ to rows and Sales to columns and filtered the ‘Customer Name’ by ‘Top 10’ by ‘Sum of Profit’.
Next, I dragged ‘Customer Segment’ to filter and selected only ‘Small Business Segment’. Ideally, there should be 10 bars showing Sales for our top 10 customers but there are only four. So, what just happened?
To understand this, it is useful to know the order in which Tableau manipulates and filters data when producing your view. This process is called ‘Order of Operations’ (actions performed in Tableau are also known as operations). It is useful to know this order so you can use it to your advantage when using any kind of filter or level of detail calculation, or if you ever find yourself confused as to why Tableau isn’t producing the results you want.
The Tableau order of operations includes all the elements in the following illustration. Filters are shown in blue; other operations, which are mostly calculations, are shown in black.
We see in this illustration that there’s a Context Filter that’s higher in order than Dimension filters and Top N filters.
So, getting back to our problem, the view is filtered but instead of 10 names, it is showing 4. This is because all filters are evaluated separately, and the view shows the intersection of the results. So, this view shows that four of the top overall customers are in small business customer segment.
To get top ten customers in small business segment we need to make Segment filter a Context Filter. Right click the segment field on filters shelf and select Add to Context. This will make the pill grey.
The filter is marked as a context filter and the view updates to show the top ten customers by profit in small business customer segment.
Context filters can filter only discrete/categorical fields. The purpose of context filters is to allow dimensions to be filtered earlier in the order of operations which means that these filters are executed before any other filter that you create in worksheet.
To understand Tableau’s order of operations in detail, see this great video: Understanding Tableau’s Order of Operations