Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Imagauthamam
Helper II
Helper II

RANK and RANKX DAX function

Hi All,

 

I'm currently learning RANK and RANKX Dax functions.
Can someone explain the difference between these 2 functions and on what scenarios you use each of these DAX functions.
Is there something which is possible in one but not possible in the other and which you do you use most and why?

 

3 REPLIES 3
Deku
Responsive Resident
Responsive Resident

RANKX came out first.

 

RANK was introducted with all other window functions to support visual calculations

andrewsommer
Advocate V
Advocate V

I think this is one a lot of people struggle with.  There is a significant difference between these two unlike SUM and SUMX that are somewhat similar.

 

RANKX: calculates the rank of a value among all possible values derived from the evaluation of an expression across all rows in a table. It provides a rank number based on evaluating the expression for each row, with the default sort order being descending.

 

RANK: In contrast, RANK returns the ranking for the current context within a specified partition, sorted by the specified order. If no match is found, the rank is returned as blank. The default sort order for RANK is ascending.

When used in a measure, RANKX cannot use a column to define the rank order in the expression, while RANK can.

RANK is preferred over RANKX when it comes to handling ties and sorting blanks.

We almost always use RANK and rarely ever use RANKX

danextian
Super User
Super User

Hi @Imagauthamam 

RANK function makes ranking on multiple columns much simpler as it allows sorting by multiple columns as a native feature. Doing this with RANKX will require some DAX acrobatics. This blog from SQLBI explains the difference quite well and also provides some examples - https://www.sqlbi.com/articles/introducing-the-rank-window-function-in-dax/ 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements