×

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.

### KeepWatch by InterWorks

Whether you need support for one platform or many, our technical experts have you covered.

## Beth Kairys

Say Less: How To Ensure Your Tooltips Add Value We’ve all done it. We’ve completely ignored the warning label. You know, the one we probably see everyday: CAUTION: Contents Hot We ...
My Top Five Tableau Prep Solutions Tableau Prep has tons of options, and you may have seen gurus pull off some truly fantastic tricks. But what should you focus on? ...

See more from this author →

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

×