Dynamic Top N: let a slicer choose how many products to show

Show sales only for the top N products, with N picked on a slicer, and a total that adds up to just those products.

You will learn to

  • Drive TOPN with a parameter slicer
  • Use a TOPN table as a CALCULATE filter with KEEPFILTERS
  • Make the total equal the sum of the products shown

How it works

A **Top N** report usually needs N to be flexible: top 3 for the executive slide, top 10 for the buyer. The `'Top N'` parameter table holds 3, 5 and 10; read it with `SELECTEDVALUE('Top N'[Top N], 5)`.

`TOPN(n, ALL(Product[Product]), [Total Sales])` returns the n best products. `ALL` makes sure every product competes, not just the one in the current row, while the Year slicer still applies to the sales used for ranking.

Used as a filter, that table needs care. A plain `CALCULATE(…, topTable)` **replaces** the row's product filter, so every bar would show the top-N total. Wrap it in `KEEPFILTERS` to **intersect** instead: a product in the top N keeps its own sales, the others go blank, and the total row shows the top N combined.

Practice it hands-on with a real data model and a live report that updates as you type.

Top Regions Sales =
VAR best = TOPN(2, ALL(Customer[Region]), [Total Sales])
RETURN CALCULATE([Total Sales], KEEPFILTERS(best))