WMA Hub

Tools / DAX library

Top N products

Show sales only for the top N products and blank for the rest.

Ranking & Top N · Intermediate · Not yet reviewed

Top 5 Product Sales =
VAR TopN = 5
VAR ProductRank = [Product Sales Rank]
RETURN
    IF(ProductRank <= TopN, [Total Sales])

How it works

The measure reuses the rank from [Product Sales Rank] and returns sales only for products ranked 5 or better, so other products show as blank and drop out of the visual.

To let users choose N, replace the 5 with a value read from a what-if parameter table, for example SELECTEDVALUE('Top N'[Top N Value], 5).

What your model needs

- The [Product Sales Rank] measure from the ranking formula. - Total Sales = SUM(Sales[Amount]) (called [Total Sales]).

Small example

Input data

Product | Total Sales
A | 500
B | 300
C | 150
D | 50
(N = 2)

Expected result

Product | Top N Product Sales
A | 500
B | 300
C | (blank)
D | (blank)

Common mistakes and limitations

- The total row is blank because the rank is blank when several products are in context. Add a separate total measure if you need one. - The visual's built-in Top N filter is simpler when you do not need the value inside other calculations.

Tags: Top N, RANKX, ranking