Cheat Sheets/Power BI/TOPN
DAX function

TOPNDAX function reference

Top N rows by an expression.

Syntax

dax
TOPN(<n_value>, <table>, <orderBy_expression>, [<order>], [<orderBy_expression2>, <order2>, …])

Examples

dax
TOPN(5, Product, [Total Sales], DESC)
A table

TOPN returns a table, so SUMX re-evaluates the measure per row to total just those top rows.

dax
SUMX(TOPN(3, VALUES(Product[Name]), CALCULATE(SUM(Sales[Amount])), DESC), CALCULATE(SUM(Sales[Amount])))
Sum of just the top 3 products' sales
dax
TOPN(5, Product, Product[Category], ASC, Product[Name], ASC)
Top 5 rows sorted by two columns, useful when the first column has ties

Common mistakes & gotchas

Related DAX functions

From Tables & set operations

← Back to the Power BI (DAX) cheat sheet