Dynamic Top N with Sets and Parameters

by Tanya Fischer

Tableau is all about interactivity and giving the user of a dashboard the option to choose a view. Let’s say we want to give the user the possibility to see the Top N states by profit. N in this case is the number he or she can choose, so either Top 5, Top 10 or.. you get the idea.

We’re starting off with a simple parameter, that is an integer with the current value of 5 and then the option to choose between a range from 5 to 20 in steps of 5:

Next up we are creating a set based on the field “State” by right clicking it and choosing “Create Set”. Under the “Top” Section we can choose a formula or in our case a field by which we want to rank our states. In our case we select Profit and then Sum:

So now when we drag Profit onto Columns and our new set and the state field onto Rows we get two categories of states – states that are in our set (in this case the Top 5 states) and states that are not in our set (all those not in the Top 5).

But so far this is not looking to good and is in no way interactive. So first of all we want to filter all of our states by profit to check whether our set is correct so far (the Top 5 should stay the same). Next up we might want to drop the set onto our colour mark as well so that we can immediately distinguish between the Top N states and the rest. To make our view dynamic we go back into our set by clicking “Edit Set” when right clicking onto the set. In our Top configuration we can replace our value of 5 with the parameter:

Last but not least we want to show the parameter on the view which will give us a slider for the range between Top 5 and Top 20 states by profit: