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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Rankx why we have to add Calculate in the expression part?

Hello,

I have tried the RankX function in a measure (and not in a column) but i am not sure to understand, what happened :

I mean when i don't add the Calculate function, The rank function stay to 1

 

RankMeasureFail2 = RANKX(ALL(Table1),SUM(Table1[Price]))

But this measure works : RankxMeasure = RANKX(ALL(Table1),CALCULATE(SUM(Table1[Price])))

 

A screen about my data :

Vlad997845_1-1606640252642.png

 

 

 

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , In Rankx and X function, you need to add calculate to make sure calculation get evaluated properly 

 

Refer, it has been explained here
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
wdx223_Daniel
Super User
Super User

@Anonymous RANKX function creates a row context, the second parameter works on the context. if you just use SUM(), this works on current filter context, ie sum of all the price, then all the row in the same position. if add a CALCULATE function, then it transform current row context into filter context, then the sum is only of the rows filtered by this transformed context, ie sum of rows which is identical with current row.

 

CNENFRNL
Community Champion
Community Champion

Hi, @Anonymous , it's all about some fundamental concepts in DAX, namely evaluation context and context transition. You might want to refer to the articles I linked or google them yourself.

 

As to RANKX ( <Table>, <Expression> [, <Value>] [, <Order>] [, <Ties>] ), <Table> is iterator, providing row context to <Expression>. One of the most remarkable features of CALCULATE()/CALCULATETABLE() functions is context transition, the row context is transited to filter context for the calculation of expression parameter, i.e. SUM(Table1[Price]) here.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.