How to create Dynamic TOP N in Tableau

Do you know how to create Dynamic TOP N in Tableau?

Follow along to the video or check out the steps below.

Let’s create a control to dynamically change the number of rows we want to see in our graph.

how to create Dynamic TOP N in Tableau

  1. Create a new parameter called “Top N” and set the type to Integer and the current value to 10.
    Right click it and select Show Parameter.

how to create Dynamic TOP N in Tableau

  1. In a new Sheet, bring the Country/Region and the Product name to the Rows shelf.
    Also, bring the Sales to the Columns shelf and to the Label

  1. Create a new calculated field called “Sales Rank” with the following formula:
    RANK(SUM([Sales]))
    Right click it and Convert to Discrete.
    Bring it to the Rows shelf, between the two existing pills.

how to create Dynamic TOP N in Tableau

  1. Right click the Sales Rank pill in the Rows shelf and select Edit Table Calculation.
    Compute using: Specific Dimensions
    Country/Region and Product Name
    At the level: Deepest
    Restarting every: Country/region

  1. Create a new calculated field called “Show Me N” with the following formula:
    [Sales Rank] <= [Top N]

  1. Put the newly created Show Me N in the Filter shelf and select the True value.

how to create Dynamic TOP N in Tableau

  1. Now you can format the numbers, change the colours and etc.

How to guides for Tableau beginners