Click to view on Tableau Public – Parameter Controlled Filter for Your Top Values
Often when viewing reports the user will want to be able to choose how many results they see rather than having that decision made for them by the report creator. There is no built-in filter for this because you need to filter by rank. To achieve this you can use a custom filter. I’ll explain below how to achieve this and I’ll use the Order data from the EU Superstore sample data for this example.
Open Tableau and connect to the EU Superstore Order data.
Create a new sheet and drop country onto the details pill and double click profit. You will now have a map with points on each of the 15 countries but what if you only wanted to see the top 3 most profitable countries?
Create a parameter called “TopX”, set the data type to integer and the current value to 3.
Now we need to rank the most profitable countries from most profitable to least profitable. We do this by right clicking on Profit in measures and then selecting Create > Calculated Field. Call the calculation “Rank” and enter the following calculation:
Before hitting OK select “Default Table Calculation” highlighted in blue above“OK”. Change “Compute using:” from “Automatic” to “Country” and then select OK and OK again.
Drop the newly created “Rank” measure onto label and you will see the values are now labelled from largest to smallest.
Create another calculated field called “RankFilter” and enter the following calculation:
IF [Rank] <= [TopX] THEN ‘Show’ ELSE ‘Hide’ END
Drag the newly created “RankFilter” measure into the filter card and tick “Show”. Make sure you leave “Hide” unticked. Select OK and you will now only see the top 3 most profitable countries.
Right click on the TopX parameter and click “show parameter control”. You will now see this parameter and you are able to change this value. Change it to 2 and you will notice that only the top 2 countries remain.
Format the map to look how you want and there you have it. You now have a parameter controlled filter which allows the user to see the TopX most profitable countries!
View the finished dashboard on tableau public here