TOPN

TOPN Returns the top N rows of the specified table.


Syntax

TOPN(n_value, table, orderBy_expression, [order[, orderBy_expression, [order]]…])

Parameters

n_value – The number of rows to return. It is any DAX expression that returns a single scalar value, where the expression is to be evaluated multiple times (for each row/context).

See the remarks section to understand when the number of rows returned could possible be larger than n_value.

See the remarks section to understand when an empty table is returned.

table – Any DAX expression that returns a table of data from where to extract the top ‘n’ rows.

orderBy_expression – Any DAX expression where the result value is used to sort the table and it is evaluated for each row of table.

order – (Optional) A value that specifies how to sort orderBy_expression values, ascending or descending:

0 FALSE – Sorts in descending order of values of order_by.

This is the default value when order parameter is omitted.

1 TRUE – Ranks in ascending order of order_by.

Return Value

A table with the top N rows of table or an empty table if n_value is 0 (zero) or less. Rows are not necessarily sorted in any particular order.


Reference Data

https://docs.microsoft.com/en-us/dax/dax-function-reference

DAX Functions / Statistical Functions / TOPN