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
Anonymous
Not applicable

Dynamic Ranking on Bases of multiple columns(Category and Sub-Category)

Hi Team,

 

we have a requirement to create the Dynamic rank. 

 

we have a  data like Category and sub-Category and profit. we need to create the dynamic Ranking for Category, Sub-Category over the profit. in the high level category wise it will disply the ranking and we click on the expand button rank should be disply on the subcategory wise ranking. for your refrence attaching the data images.

 

 

High levelHigh levelLow levelLow level

 

Please do needful

 

Thanks

Koushik

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi Team

 

I have written the below code Some how it's working

 

Rank = IF(ISFILTERED('Order Data'[Product Name]),RANKX(ALL('Order Data'[Product Name]),[Total Profit],,DESC),IF(ISFILTERED('Order Data'[Sub-Category]),RANKX(ALL('Order Data'[Sub-Category]),[Total Profit],,DESC),IF(ISFILTERED('Order Data'[Category]),RANKX(ALL('Order Data'[Category]),[Total Profit],,DESC))))

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi Team

 

I have written the below code Some how it's working

 

Rank = IF(ISFILTERED('Order Data'[Product Name]),RANKX(ALL('Order Data'[Product Name]),[Total Profit],,DESC),IF(ISFILTERED('Order Data'[Sub-Category]),RANKX(ALL('Order Data'[Sub-Category]),[Total Profit],,DESC),IF(ISFILTERED('Order Data'[Category]),RANKX(ALL('Order Data'[Category]),[Total Profit],,DESC))))
mahenkj2
Solution Sage
Solution Sage

Hi @Anonymous ,

 

Please create a measure for Profit:

Profit = 
SUM ( 'Table'[Total profit] )

Then use this measure in final rank formula:

 

Rank Name Simple = 
IF (
    HASONEVALUE ( 'Table'[Category] ),
    RANKX ( CALCULATETABLE('Table', REMOVEFILTERS('Table'[Sub category])), [Profit] )
)

 

basically, what we are doing, is removing filters from Sub category with the help of CALCULATETABLE function.

 

Hope it helps.

 

johnt75
Super User
Super User

The SQL BI guys have a great article on this at https://www.daxpatterns.com/ranking/ 

Anonymous
Not applicable

Hi Johnt,

 

I'm following the same url but not getting proper result,can you please help me with code.

please find the dax code i was written.

 

Rank in Category =
VAR SalesAmountCurrentProduct = 'Order Data'[Total Sales]
VAR ProductsInCategory =
CALCULATETABLE (
'Order Data',
REMOVEFILTERS ( 'Order Data'[Sub-Category] ),
ALLSELECTED ( 'Order Data' ),
VALUES ( 'Order Data'[Category] )
)
VAR ProductRank =
IF (
ISINSCOPE ( 'Order Data'[Sub-Category] ),
RANKX (
ProductsInCategory,
'Order Data' [Total Sales]
)
)
VAR Result =
IF (
NOT ISBLANK ( SalesAmountCurrentProduct ),
ProductRank
)
RETURN
 
 
getting the results like below
 
ResultCapture2.PNG

I don't see any real difference from the code in the article. What is the definition of [Total Sales] ?

Anonymous
Not applicable

Total Sales = SUM('Order Data'[Sales])

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Solution Authors
Top Kudoed Authors