Your Best Basic Friend: Tableau’s Order of Operations
When using Tableau, you almost always want to add filters, so that your data can answer more questions. It can be filters applied on table calcs, context filters or filters for sets or LOD expressions – but nevertheless, everybody filters in some way. So, since they are all filters, Tableau should just execute them in the order you made them, right?
The answer is no. Your filters will be applied according to Tableau’s Order of Operations as seen below.
Sometimes this can cause your view to end up not quite the way you intended it to be, because your filter will not apply on the operation that you want it to filter on since that operation is higher up in the hierarchy – but luckily this can often be fixed by changing the kind of filters you have applied. For instance, you can convert your dimension filter to a context filter, or you can change your table calc to an LOD expression depending on your situation.
I will now demonstrate a case using Tableau's Super Store data where it would be a good idea to change a dimension filter to a context filter. In my view, I would like to have an overview of how well my products are doing in the state of Arizona. Thus, I create this view:
Okay, so it looks like Arizonians like phones and chairs a lot, closely followed by tables, accessories and storage. Interesting. Actually, I am only interested in my top 5 sellers, so let me add another filter showing only this. I can do this by dragging my Sub-Category dimension to filters and choosing to see only top 5. Doing this, I end up with this view:
Okay, so I now have a better overview telling my that my top 5 sellers in Arizona is phones, chairs, tables and... But wait, what happened with accessories? Why is the top 5 now concluded with storage and binders instead of accessories and storage? Either something happened in Arizona during the last couple of minutes that made Arizonians dislike accessories - or we are looking at an Order of Operations issue here. I'm guessing it's the second one, so let's have a look at what I did in regards to filtering.
I applied two filters - first the state filter and then the top 5 products filter. As you can see from the Order of Operations pic above, a dimension filter won't work on a Top N filter, which is exactly what I am trying to make it do - so what I see in my current view is actually the overall top 5 sellers in the States, not the top 5 sellers in Arizona. Another look at the Order of Operations pic tells me that making my state filter a context filter instead of a dimension filter might help. Let's try that:
It worked! Now accessories are back in the Arizonian top 5, and my analysis will show the correct results.
So, keep Tableau’s handy Order of Operations pic nearby when working in Tableau – it can save you from some frustrations over filters being applied in a, at first, seemingly weird way. And it can be useful for both beginners and pro users!