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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
bestevez
Helper I
Helper I

RANKX AND ORDER

Hello,

 

I have a question I'd like to raise so that I can resolve it. As you can see in the table I would like to add a column (RANKX ORDER LY) where appears the ranking of last year's products that had the same order as this year's products. 

 

The RANKX and RANKX LY columns work perfectly.

 

YEARPRODUCTQTYRANKX  
2018PEPSI501  
2018COCA COLA452  
2018ORANGE303  
2018PEPSI MAX254  
2018COCA COLA ZERO105  
      
      
   RANKXRANKX LYRANKX ORDER LY
2019COCA COLA5512PEPSI
2019PEPSI MAX4024COCA COLA
2019PEPSI3531ORANGE
2019COCA COLA ZERO3045PEPSI MAX
2019ORANGE2853COCA COLA ZERO

 

Thanks

3 REPLIES 3
MartynRamsden
Solution Sage
Solution Sage

Hi @bestevez 

 

Not sure if I'm over simplifying things but I think you could use the LOOKUPVALUE function as follows.

 

RANKX ORDER LY = LOOKUPVALUE ( 'Table'[PRODUCT], 'Table'[RANKX LY], 'Table'[RANKX] )

 

Best regards,

Martyn 

danielkinch
Frequent Visitor

Hello.

 

I do have a suggestion, albeit not a particularly elogant solution...

 

To achieve the table shown I would suggest first create the RANKX formula in your data table:

RANKX =
RANKX(
    FILTER(
    data_table,data_table[YEAR]=EARLIER(data_table[YEAR])),
data_table[QTY])

 

You can then use this to create a calculated table as follows:

RankLY = SUMMARIZECOLUMNS(data_table[YEAR],data_table[PRODUCT],data_table[QTY],data_table[RANKX])
 
Back in your main data table you can then create two calculated columns which call back the desired values:
 
RANKX LY = LOOKUPVALUE(RankLY[RANKX],RankLY[YEAR],data_table[YEAR]-1,RankLY[PRODUCT],data_table[PRODUCT])
And.... 
RANKX ORDER LY = LOOKUPVALUE(RankLY[PRODUCT],RankLY[YEAR],data_table[YEAR]-1,RankLY[RANKX],data_table[RANKX])
 
Hope this maybe of some use to you 😊

Thanks i try it. 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.