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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Roberto456
Resolver I
Resolver I

RankX with 2 fields

Hello All.

 

For some reason 1 RankX formula works but the other doesnt.

 

Below is Dax:

 

Product Rank (Name) =

VAR CURRENTPRODUCT = MAX('(Dim) Product'[Product_Name])
RETURN
RANKX(FILTER(ALLSELECTED('(Dim) Product'),'(Dim) Product'[Product_Name] = CURRENTPRODUCT),[Master],,DESC,Dense)
 
Product Rank (Category) =

VAR CURRENTCATEGORY = MAX('(Dim) Product'[Category])
RETURN
RANKX(FILTER(ALLSELECTED('(Dim) Product'),'(Dim) Product'[Category] = CURRENTCATEGORY),[Master],,DESC,Dense)
 
 For some Reason the Name one works but the Cateogry doesnt, even though they are the both exact same DAX.
 
product name.JPGCategory.JPG
 
Can anyone help me fix this?
5 REPLIES 5
v-kelly-msft
Community Support
Community Support

Hello @Roberto456 ,

Your formulas are calculated columns, right?

If so, modify them as follows:

Product Rank (Name) = 

RANKX(FILTER(ALLSELECTED('(Dim) Product'),'(Dim) Product'[Product_Name] = EARLIER('(Dim) Product'[Product_Name])),[Master],,DESC,Dense)
Product Rank (Category) = 
RANKX(FILTER(ALLSELECTED('(Dim) Product'),'(Dim) Product'[Category] =EARLIER('(Dim) Product'[Category] )),[Master],,DESC,Dense)
 

Saludos
Kelly
Did I answer your question? Mark my position as a solution!

Hello.

 

I found the solution.

 

No these are measures, for dynamic ranking.

 

The problem was, that unless I put in the 2nd field as the most granular part of the product (from the table being referenced) the ranking wouldnt work.

 

which is why category / product wouldn't work, (product wasnt the most granular field).

 

I had to duplicate the product table and make sure that product name was the most granular field and then reference that table instead.

 

I would have preffered to use a VAR table, but I couldnt find a way to RankX from it.

v-kelly-msft
Community Support
Community Support

Hi @Roberto456

 

 Your formulas are calculated columns,right?

If so ,modify them as below:

 

Product Rank (Name) = 

RANKX(FILTER(ALLSELECTED('(Dim) Product'),'(Dim) Product'[Product_Name] = EARLIER('(Dim) Product'[Product_Name])),[Master],,DESC,Dense)
Product Rank (Category) = 
RANKX(FILTER(ALLSELECTED('(Dim) Product'),'(Dim) Product'[Category] =EARLIER('(Dim) Product'[Category] )),[Master],,DESC,Dense)
 

 

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

amitchandak
Super User
Super User

@Roberto456 , It Seems like you are creating a subcategory rank.  Now rank will change based on context. So I rank a measure on product . If I use the product then it will show correct rank. But If Add Category, then it will show product rank inside the category.

 

But If add say Product ID then I will see all 1. In such case In need use All(product,prodcut_id) to make sure they work together

 

For Rank Refer these links

https://www.sqlbi.com/articles/use-of-rankx-in-power-bi-measures/
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
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

 

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
parry2k
Super User
Super User

@Roberto456 check these post for rank

 

https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
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-3-of-3-the-finale

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.