Downloads
DAXRanking and windowsAdvanced

ROWNUMBER

Gives each row of an ordered list a sequence number, starting from 1.

Syntax
ROWNUMBER([<relation>], [<orderBy>], [<blanks>])

Returns: A whole number for the current row.

What it does

ROWNUMBER numbers the rows of an ordered list, so the first row is 1, the second is 2, and so on. The numbers come from the sort order you choose, not from the order rows sit in the data. Use it to number items in a visual, or as a step before a filter that keeps the first few rows. Check that your version of Power BI supports it, and confirm the arguments in the Microsoft reference, because this is one of the newer functions.

Syntax and arguments

Example

A sequence number for each date in the current selection, shown in a table next to the dates.

Day Number =
ROWNUMBER (
    ALLSELECTED ( 'Date'[Date] ),
    ORDERBY ( 'Date'[Date] )
)

The earliest date in the selection gets 1, the next gets 2, and so on. The number is based on the date order, so it stays the same when the report is sorted another way.

Things to watch

In business terms

Numbering invoices or journal lines in a review sample, giving each period in a selection a sequence for a chart, and marking the first few rows of a sorted list for a top-N style review.

Related functions

All DAX functions · View as Markdown · DAX fundamentals