Forum Discussion

erihsehc's avatar
erihsehc
Helper III
8 years ago
Solved

ranking error

rank customer = RANKX(ALLSELECTED(Table1),CALCULATE(SUM(Table1[sales]),ALLEXCEPT(Table1,Table1[Customer],Table1[factory])))

so strange that A and B are at same rank, what is the problem here? thanks

  • Dog's avatar
    Dog
    8 years ago

    Hi, 

     

    Looks like the Ranking is correct on that screen shot as it's performing the ranking at customer level for each factory.
    you'd need to adjust the RANKX statement to perform the ranking at factory level to change the values.

    I do something similar and I check to see what's filtered and amend the measure accordingly.

     

     

    try this instead. 

     

    RankCustomer =
    IF(HASONEVALUE(Table1[factory]),
    RANKX(ALLSELECTED(Table1), CALCULATE(sum(Table1[sales]), ALLEXCEPT(Table,Table1[Customer], Table1[factory]))) ,
    RANKX(ALLSELECTED(Sheet1), CALCULATE(sum(Sheet1[sales]), ALLEXCEPT(Sheet1,Sheet1[Customer])), ,DESC,Dense) )

8 Replies

  • Dog's avatar
    Dog
    Responsive Resident

    Hi erihsehc,

     

    I assume it's due to the Factory column included in your ALLEXCEPT function, this would work if you were displaying the column I think. 

     

    using the following works for me. (using my own column and table names)

     

    RankCustomer = RANKX(ALLSELECTED(Sheet1), CALCULATE(sum(Sheet1[sales]), ALLEXCEPT(Sheet1,Sheet1[Customer])), ,DESC,Dense)

     

    Dog

    • erihsehc's avatar
      erihsehc
      Helper III

      Thanks Dog. I have tried the formula, the ranking is correct but the factory slicer is not working, the ranking remain unchanged when I select different country. how to make the ranking correct and also the slicer works? thanks

      rank customer = RANKX(ALLSELECTED(Table1),CALCULATE(SUM(Table1[sales]),ALLEXCEPT(Table1,Table1[Customer])),,DESC,Dense)

       

      • v-ljerr-msft's avatar
        v-ljerr-msft
        Microsoft Employee

        Hi erihsehc,

         

        Based on my test, the formula below should work in your scenario. :smileyhappy:

        rank customer = 
        RANKX (
            ALLSELECTED ( Table1 ),
            CALCULATE ( SUM ( Table1[sales] ), ALLEXCEPT ( Table1, Table1[Customer], Table1[factory] ) ),
            ,
            DESC,
            DENSE
        )
        

         

        Regards