There are times when I like to see every dimension member represented in a data visualization. For example, scatter plots are a great choice whenever you are wanting to view many data points in the same space. I’ll also occasionally create a bar chart or histogram with every dimension member, even if it causes a vertical or horizontal scroll bar to appear.
While the “long-tail” insights these charts can provide have value, I tend to focus on the few dimension members causing the biggest impact on the business I’m analyzing. For this reason, I often show the Top N (i.e. usually Top 5 or Top 10) and group everything else into its own segment. And while I don’t advocate the use of pie charts (here are 3 better options), I do always say that if you must use them, stick to five slices or fewer including “Other”. This is how you do it.
This post will demonstrate how to dynamically display the Top N based on the number of dimension members the end user wants to show and how to group everything else into a segment for “Other”.
This is a preview of the Two Ways to Dynamically Display the Top N vs Other in Tableau video at Playfair Data TV.
How to Dynamically Display the Top N vs Other in Tableau
The first step to showing the dimension members of the Top N and grouping everything else into one line is to create a parameter for the Top N. This will eventually allow the end user to choose how many individual dimension members to show (i.e. Top 5, Top 6, Top 7, and so on). The allowable options are flexible and up to you, but here’s one example when I allow options between 5 and 20 in multiples of 5.
If parameters are new to you, be sure to check out An Introduction to Tableau Parameters.
Next, create a set for the dimension you want to segment. For this tutorial, I will create a set out of the State dimension in the Sample – Superstore dataset. The set will be set up to show the Top N states by the Profit measure.
To start a set, right-click on the dimension, hover over create, and click “Set…”. A new dialog will appear where you can set the conditions for which states should be included in the set. Since we are wanting to keep the “Top N” based on a specific measure, navigate to the third tab: Top.
Here you can choose a specific number to keep (the default is 10), but you can also click the dropdown located to the right of the hard-coded value and choose our newly created “Top N” parameter. Based on our parameter settings, this will keep 5, 10, 15, or 20 states in the set depending on the current selection.
To finalize the set, we’ll also want to change the measure that the set is based on to Profit. Here’s how my set looks at this point.
The next step is create a calculated field that will do the desired grouping. Here is the formula:
Top N vs Other States by Profit = IF [Top N States by Profit] THEN [State] ELSE “Other” END
Now we’re ready to use this calculated dimension in a chart. I’ll place this new calculation on the Rows Shelf, the Profit measure on the Columns Shelf, and sort the bars by profit. Also, be sure to show the parameter control by right-clicking on the Top N parameter and choosing “Show Parameter Control”. This will allow you and the end user to choose between the allowable choices of 5, 10, 15, and 20.
As you can see, when the default parameter value of 5 is selected, there are six bars; one for each of the Top 5 states by profit and one for everything else. If you always want the “Other” bar on the bottom, place the “Top N States by Profit” set we created earlier as the first field on the Rows Shelf. This will break up the sets of bars depending on whether or not they’re in the Top N.
You can always hide the first header for In vs Out by right-clicking on it and deselecting “Show Header”. Now the end user can choose to group the top 5, 10, 15, or 20 and everything else into it’s own segment called “Other”! Here’s how my final view looks after cleaning up the formatting and changing the Top N parameter to 10.
Thanks for reading,