During a consulting day, I was asked to create a dashboard with two worksheets:
- Top 20 Customers based on a measure.
- Bottom 20 customers based on the same measure.
According to the customer requirements, the user should be able to select a number N and then both views will be updated.
In Tableau, you can easily answer the same questions by creating a single worksheet. You only need to create the necessary interactivity. Let’s see how we can do this!
Initially, I created a single view with a Rank table calculation on the filter shelf. In this case, the user can either move the slider left/right and filter the view or type in the min/max value he/she wants to see:
However, the user came back to with the following feedback:
“I would like to select between Bottom and Top customers by clicking a button. In addition, I would like to select one number only and not two numbers as in the slider. Is it possible?”
The answer is positive and the wishful result can be achieved by creating two Parameters and one Calculated Field. Let’s see how.
Firstly, a Parameter which will be the button that the user will use to switch between Top and Bottom customers.
Secondly, a Parameter which will allow the selection of the number of customers.
Lastly, a Calculated Field which we will place on the filter shelf and select True to keep only the selected values in the view.
Size: Returns the number of rows in the partition. Details can be found here.
Rank: a Rank table calculation computes a ranking for each value in a partition. Details here.
There are 793 unique customers in our dataset.
When the user selects Top and 20 then the calculation is True only for the customers which are ranked from 1st till 20th.
When the user selects Bottom and 20 then the calculation is True only for the customers which are ranked from 793rd till 774th.
You can find the resulting workbook here if you want to take a look.