Skip to main content

Give examples of Power BI/DAX functions that are very similar to SQL window functions.

Table of Contents

The DAX functions Offset, Window and Index all perform calculations across a set of table rows related to the current row, much like SQL window functions. However, differing from SQL window functions, they do rely on the DAX evaluation context to define the “current row.” These DAX functions do not return a single value but instead they return a set of rows. This set of rows can then be used with other DAX functions, like CALCULATE or SUMX, to compute a value.


The INDEX function retrieves a row by its absolute position in the table.

The OFFSET function retrieves a row using its relative position to the current row.

The WINDOW function retrieves a slice of rows that are filtered or sorted in a specific way.

The RANK and ROWNUMBER functions, introduced in April 2023, are DAX functions that work similarly to window functions. Both return the ranking of the current row within a specified partition, sorted by a defined order. The key difference between the two is how they handle ties (when two rows have the same value for the ranking column).

RANK assigns the same rank to all tied rows. For example, if two rows have the highest sales value, both will be given a rank of 1.

ROWNUMBER, however, assigns a unique rank to each row, even in the case of ties. For example, if two rows share the highest sales value, ROWNUMBER will assign rank 1 to the first row and rank 2 to the second.

ROWNUMBER will return an error if it cannot uniquely identify every row in the partition. However, it will try to avoid this by appending the least number of additional columns needed to uniquely identify each row and include them in the ORDER BY clause.

Examples of using RANK and ROWNUMBER:

RANK(Sales, ALLSELECTED(Products), ORDER BY(Products[Sales]))
ROWNUMBER(ALLSELECTED(Customers), ORDER BY(Customers[TotalOrders]))

Add comment