Skip to content

Solved! Tableau Filtering Issue Tutorial

  • February 8, 2023

Have you ever encountered a filtering issue in Tableau that you were close to solving but just...not quite there? You may need to create a set! A few months ago, I was having a heck of a time with a Tableau visualization that I was creating for a client.  

This client has members (their customers) that in turn sell to companies (the members’ customers) for which I needed to show the top five based on sales from the current year (2022) and display sales for the past few years (’20, ’21 & ’22). I created an LOD calculation to assign rank as it had to be unique to the member, their customer, and the year, but when I tried to filter by that rank, I would lose the ability to display sales for previous years (because duh, the LOD was tied to current year). 

Image1

I realized this was a job for a set…I created one based on the following formula: 

sum({FIXED [Year], [Member],[Company],[Sales] : sum(if [Year]=2022 then [Sales] END)})* 

Image2

 

I was getting closer, but still, what Tableau considered to be “in” my set and “out” of it didn’t look quite right – why was it considering a company that was ranked “3” to be out of the set? It was almost as if it wasn’t taking into account the member’s name I had filtered on. 

Image3

In a way, that’s what was happening. I did some searching online, and lo and behold, one of the Flerlage Twins had the answer for me - IT’S AN ORDER OF OPERATIONS THING. It was computing the set (finding the top 5) before it computed my filters (filtered by member name). 

https://community.tableau.com/s/question/0D54T00000C6pDoSAJ/created-set-doesnt-work-as-it-is-supposed-to-do?t=1655846286627 

The solution is to right-click on the filter name (in this case, Member) and select “Add to context”. This gives that filtering priority over the set and then the in/out set was calculated properly. 

Image4

At this point, my rank field is just performative, and I don’t need it at all. In fact, because it’s based on the 2022, you’ll notice that there is a NULL rank value for previous years, which just looks sloppy. Here’s my final result: 

Image5

I’ve created a story board and published this to Tableau Public, in case it's of use to you, too! 

https://public.tableau.com/views/SetSample/SetDashboard?:language=en-US&publish=yes&:display_count=n&:origin=viz_share_link 

 

*Because I’m publishing this in 2023 and my dummy data set doesn’t have 2023 data, I’ve hardcoded ‘2022’ in my formulas. If you visit Tableau Public and download my workbook, you’ll see I’ve created a field to display the current year, and you can change the formula to be dynamic by replacing ‘2022’ with [CurrentYear]. 

 

RELATED NEWS

Contribute on my charity work by your donation.

Easy Button: Alteryx Server Log Collection

Collecting Logs for Alteryx Support 

Background

Occasionally you may encounter an issue with your Alteryx server that...

by Conrad Kite

The Power of Snowflake and FactSet

The days of hosting big technology and staff or spending thousands to access fast information are over. The Data Cloud...

by Andy Leichtle