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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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

Share with Power BI Enthusiasts: 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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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