TOPN DAX Function (Table manipulation)

Returns a given number of top rows according to a specified expression.


TOPN ( <N_Value>, <Table> [, <OrderBy_Expression> [, [<Order>] [, <OrderBy_Expression> [, [<Order>] [, … ] ] ] ] ] )
Parameter Attributes Description

The number of rows to return.


An expression that defines the table from which rows are to be returned.

Row Context

Expression to be used for sorting the table.

Order Optional

The order to be applied. 0/FALSE/DESC – descending; 1/TRUE/ASC – ascending.

Return values

Table An entire table or a table with one or more columns.

A table with the top N_value rows of Table or an empty table if N_value is 0 (zero).


If there is a tie, in OrderBy_Expression values, at the N-th row of the table, then all tied rows are returned. Then, when there are ties at the N-th row the function might return more than n rows.

If N_Value is 0 (zero) then TOPN returns an empty table.

TOPN does not guarantee any sort order for the results.

Related articles

Learn more about TOPN in the following articles:

Related functions

Other related functions are:

Last update: Nov 20, 2020   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

MSDN documentation:

Black Friday
2018-2020 © SQLBI. All rights are reserved. Information coming from MSDN is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.


Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.


This function is deprecated. Jump to the Alternatives section to see the function to use.


This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.


Want to improve the content of TOPN? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.