Advance with Assist: Dynamic Sort with Top N

Data

Advance with Assist: Dynamic Sort with Top N

Question: I’d like to show the top items by a measure but allow my user to select the measure (e.g. swap between top 5 on Sales and top 5 on Profit). AND I want them to be able to change the number of top items (e.g. top 5 or top 10). How can I do this? 

The Challenge

We’ve got some categories and are showing multiple measures for them. For example, below we’ve got Sales and Profit by Sub-Category and limited to our top 10 items on Sales:

But now, our user wants to look at this for the top 10 on Profit and then top 5 on Profit. How can we bake in this flexibility?

The Solution

We’re going to build a few parameters to drive our sort and give us our top N. Parameters are great tools – your user can pick what they are interested in, and if you need to add something else to the list in the future, you can!

Parameter 1

Our first parameter is for our sort options. For now, we’re making parameters with our core items: Sales and Profit:

We need a calculation that turns this into something we can reference. We’ll make a simple one that just calls up sum(sales) if Sales is selected, and sum(profit) if Profit is selected:

Finally, we’ll tell Tableau to sort by that calc, so right-click our dimension Sub-Category in Rows, and set to Sort by Descending:

Parameter 2

Now, let’s make another parameter for Top n:

And set my filter to be based on Top n on Sort by, so my user can set the number they’re after:

PRESTO! Now, I can select my measure to Sort by and my Top n in my range. Hoorah!

To explore the data further, you can also download the Tableau workbook below.

More About the Author

Beth Kairys

Analytics Consultant
Webinar Replay: Interactive Dashboard Tips & Tricks Interactive dashboards are where Tableau really comes into its own. As a Creator, you can build something that lets your users explore ...
Date Comparisons in Tableau, Part 2: Visualization Current vs. comparison periods are one of the most common queries our Assist team receives. They’re so common I was inspired to put ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072