Forum Discussion

epmck11's avatar
epmck11
Frequent Visitor
8 years ago
Solved

Ranking sums based on condition

Hi all,

 

I'm still learning DAX, and it's a bit of an adjustment for me, so any help would be appreciated. I'm trying to rank the sums of values based on criteria. Imagine I have a table like this:

 

BranchCustomerRevenue
ABCMcDonalds$1,000
DEFBurger King$1,500
XYZWendy's$2,000
ABCBurger King$500
DEFWendy's$750
XYZMcDonalds$3,000
ABCMcDonalds$500
DEFBurger King$1,000
XYZWendy's$500

 

I want to be able to sum all the revenue for each branch and customer combination, and then rank them based on their total revenue for that branch. For instance, ABC - McDonalds would be ranked 1 as it has $1500 revenue, ABC - Burger King would be rank 2 as it has $500 revenue, DEF - Burger King would be ranked 1, DEF Wendy's would be ranked 2. How do I do this?

  • epmck11

     

    Hi, try with this measure

     

    RankbyBranch-Customer =
    IF (
        HASONEVALUE ( Table1[Customer] );
        RANKX (
            ALLSELECTED ( Table1[Customer] );
            CALCULATE ( SUM ( Table1[Revenue] ) )
        )
    )

     

    Regards

     

    Victor

3 Replies

  • Vvelarde's avatar
    Vvelarde
    Community Champion

    epmck11

     

    Hi, try with this measure

     

    RankbyBranch-Customer =
    IF (
        HASONEVALUE ( Table1[Customer] );
        RANKX (
            ALLSELECTED ( Table1[Customer] );
            CALCULATE ( SUM ( Table1[Revenue] ) )
        )
    )

     

    Regards

     

    Victor

    • epmck11's avatar
      epmck11
      Frequent Visitor

      You guys are so smart! Thanks for your help, it worked.

       

      Question though: for my Power BI, I need to use a comma instead of a semi-colon or it gives me an improper syntax error. What is the reason for this? 

      • Vvelarde's avatar
        Vvelarde
        Community Champion

        epmck11

         

        Is just Regional Settings. In my Configuration is set to ;

         

        Regards

         

        Victor