KNOWLEDGE BASE

Showing Top and Bottom N Per Category


Published: 16 Aug 2017
Last modified date: 29 Mar 2023

Question

How to show top and bottom N per category.

Environment

  • Tableau Desktop

Answer

The attached example workbook uses the example data set Superstore to demonstrate the following instructions:

  1. Create a calculated field with a name like "Top & Bottom N Filter" with a calculation similar to the following:

    RANK( SUM( [Sales] ), 'desc' ) <= [N Parameter]

    OR

    RANK( SUM( [Sales] ), 'asc' ) <= [N Parameter]

    The above calculation returns a value of true if SUM( [Sales] ) is the highest N ranking sub-categories for either largest first or smallest first.

  2. Drag [Top & Bottom N Filter] to the Filters shelf and click OK to close the Filter dialog.

  3. Right-click [Top & Bottom N Filter] on the Filters shelf and select Compute using > Pane (Down).

  4. In the Filter dialogue, tick True and click OK.

Did this article resolve the issue?