Forum Discussion

bprokop's avatar
bprokop
Frequent Visitor
4 years ago
Solved

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
  • Anonymous's avatar
    Anonymous
    4 years ago

    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 :

    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.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    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 :

    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.