Scenario
We had a use case to implement an OR Filter in the Tableau reports.
How did we Solve it?
We used relationships to achieve this. I would like to explain this with an example.
Dataset for the Use Case
Consider the below data. It has daily sales by vehicle name. This dataset has vehicle name as A,B,C,D and E.
Main Dataset
Assume, your organization had an old list of vehicles that your management people are more familiar to it and would want to see that list only, as filter on the reports. Assume, below is the old list of name of vehicles. For example, current day vehicle A was known as A LXI, A VXI, A DXI, which are now all known as only A. Similarly, others.
Old list of vehicles
User wants to see the Vehicle filter with the list of old values rather than new values. But the data that you return will be based upon the new list of vehicle name.
Example, regardless of user selecting A LXI,A VXI,A DXI, you should show the below data
Relationships to Rescue
1. Prepare the dataset as shown below, Main Dataset and Old List of Vehicles will be in relation based upon the Vehicle ID field and ensure it is Many to Many relation (default set by Tableau). No human intervention in this.
- Bring the fields from the Main Dataset into the view as shown below
- For the purpose of filter, use the vehicle name filter from the Old List of Vehicles. This is where, OR will be implemented.
Your view will appear something as shown below.
Now, observe the filtering behavior, You select A LXI OR A VXI OR A DXI, your view would always return the A vehicle data.
Output, with different filter selection
Don't you think this is the OR behavior one would expect?
How did this work?
Tableau relationships are different from Join. Had, it been a join, then records would have always duplicated regardless of you use Vehicle Name field from the Old List of Vehicles in the view or outside the view but relationship, filters the duplicates unless the field from the non-fact table is consumed inside the view. Relationship are driven based upon cardinality, referential integrity and usage of fields from the related tables/dimensions.
Refer the Tableau link for more details on relationships : https://help.tableau.com/current/pro/desktop/en-us/datasource_relationships_perfoptions.htm?source=productlink
Potential Issue : If you are already a master of relationships in Tableau, then you can ignore this, otherwise you should definitely read it.
Ensure, you use the fields from the Old List of Vehicles, only for the purpose of filtering or in parameters, As long as they are away from the View, Tableau doesn't duplicate the records and on this one single feature of of relationship, OR filtering is implemented.
See below, what happens, if you use the field from the Old List of Vehicles dataset. Your data gets multiplied based upon the number of occurrences of joining records in the Old List of Vehicles.
My Comment on the Use Case used in this Blog
You may consider, the use case I have explained is trivial and may be non-realistic but think from the perspective of How filtering is implemented and in case if you have any such scenario, whether this solution works.
Alternate Approach
You could use this old list of vehicles in a separate dataset and through parameters, you can implement this filter. While this article is being written, Tableau doesn't support multi-select parameters by native feature so you have to implement multi-select parameters through calculations, which is achievable. That approach, I will share later. But it is not feasible, if you have multiple such filters like imagine, 4 filters or 5 filters are this way.
No comments:
Post a Comment