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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bprokop
Frequent Visitor

RANK By Multiple Criteria

I am trying to calculate a National Rank and State Rank using the sample data set below.  National Rank would rank Revenue by Client and Product.  State Rank would rank Revenue by Client and Product within the State.  I am looking to replicate the 4 columns to the right in Power BI using DAX.  Any help would be greatly appreciated.

 

      High-To-LowLow-To-HighHigh-To-LowLow-To-High
ClientStateProductVolumePriceRevenueNational RankNational RankState RankState Rank 
ATX14503$23$103,5694331
ATX23696$98$362,2084313
ATX38350$50$417,5002522
ATX4674$91$61,3345231
ATX58497$20$169,9401113
BCA12185$23$50,2555222
BCA26522$98$639,1563431
BCA31393$50$69,6505222
BCA4452$91$41,1326131
BCA58216$20$164,3202513
CTX18861$23$203,8032513
CTX22650$98$259,7005222
CTX38725$50$436,2501613
CTX46441$91$586,1311613
CTX55852$20$117,0404322
DCA19240$23$212,5201613
DCA27179$98$703,5422522
DCA37469$50$373,4503413
DCA43464$91$315,2242513
DCA56463$20$129,2603422
ETX17620$23$175,2603422
ETX2330$98$32,3406131
ETX37402$50$370,1004331
ETX41805$91$164,2554322
ETX51643$20$32,8606131
FCA11312$23$30,1766131
FCA27684$98$753,0321613
FCA31349$50$67,4506131
FCA42724$91$247,8843422
FCA55109$20$102,1805231
1 ACCEPTED SOLUTION
v-yetao1-msft
Community Support
Community Support

Hi @bprokop 

I created a sample with the data you provided .

Create 4 measures separately and rank them according to different categories.

National high-low = RANKX(FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product])),CALCULATE(MAX('Table'[Revenue])),,DESC,Dense)
National low-high = RANKX(FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product])),CALCULATE(MAX('Table'[Revenue])),,ASC,Dense)
State high-low = RANKX(FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product]) && 'Table'[State]=MAX('Table'[State])),CALCULATE(MAX('Table'[Revenue])),,DESC,Dense)
State low-high = RANKX(FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product]) && 'Table'[State]=MAX('Table'[State])),CALCULATE(MAX('Table'[Revenue])),,ASC,Dense)

The final result is as shown :

Ailsamsft_0-1645772533973.png

I have attached my pbix file , you can refer to it .

 

Best Regard

Community Support Team _ Ailsa Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yetao1-msft
Community Support
Community Support

Hi @bprokop 

I created a sample with the data you provided .

Create 4 measures separately and rank them according to different categories.

National high-low = RANKX(FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product])),CALCULATE(MAX('Table'[Revenue])),,DESC,Dense)
National low-high = RANKX(FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product])),CALCULATE(MAX('Table'[Revenue])),,ASC,Dense)
State high-low = RANKX(FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product]) && 'Table'[State]=MAX('Table'[State])),CALCULATE(MAX('Table'[Revenue])),,DESC,Dense)
State low-high = RANKX(FILTER(ALL('Table'),'Table'[Product]=MAX('Table'[Product]) && 'Table'[State]=MAX('Table'[State])),CALCULATE(MAX('Table'[Revenue])),,ASC,Dense)

The final result is as shown :

Ailsamsft_0-1645772533973.png

I have attached my pbix file , you can refer to it .

 

Best Regard

Community Support Team _ Ailsa Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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