TOPN DAX Function (Table manipulation)

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

Syntax

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

The number of rows to return.

Table
Iterator

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

OrderBy_Expression
Row Context
Optional
Repeatable

Expression to be used for sorting the table.

Order Optional
Repeatable

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).

Remarks

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 functions

Other related functions are:

Last update: Dec 13, 2018   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

MSDN documentation: https://msdn.microsoft.com/en-us/query-bi/dax/topn-function-dax

DAX Conventions
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.

Iterator

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.

Deprecated

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

Deprecated

This parameter is deprecated and its use is not recommended.

Contribute

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.