Forum Discussion

Vish24's avatar
Vish24
Helper II
6 years ago
Solved

Need help with ranking

Hello,

I am really struggling in ranking my data. I have data like this:

Name   Sales  Year

A           100    2019

A           50     2019

A           25     2018

B          100    2019

B          75      2018

C          20     2019

B          45     2018

 

I have Sales by Many people with different years. One Person has many sales in a year. Now, I want to rank them for their sales by year. I am making a slicer for Names and Year. I want to show the ranking as per the selected name and year.

So my data should be rank separately for each year.

 

Please help! 

 

 

  • Hi Vish24 ,

     

    You can use a measure like this:

    Measure = 
    VAR _tmpTable = SUMMARIZE(ALLSELECTED(Table1), Table1[Name], "SalesTotal", SUM(Table1[Sales ]))
    VAR _rankedTable = ADDCOLUMNS(_tmpTable, "Rank", RANKX(_tmpTable, [SalesTotal], , DESC, Dense))
    RETURN
    MAXX(FILTER(_rankedTable, [Name] = SELECTEDVALUE(Table1[Name])), [Rank])

    Resulting in a visual like this:

     

    Kind regards

    Djerro123

    -------------------------------

    If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

    Keep those thumbs up coming! 🙂

21 Replies

  • Refer

    https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

    Check for "Ranking by Sub Category"

     

    Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
    Thanks. My Recent Blog -
    Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
    Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

    Connect on Linkedin

  • JarroVGIT's avatar
    JarroVGIT
    Resident Rockstar

    Hi Vish24 ,

     

    You can use a measure like this:

    Measure = 
    VAR _tmpTable = SUMMARIZE(ALLSELECTED(Table1), Table1[Name], "SalesTotal", SUM(Table1[Sales ]))
    VAR _rankedTable = ADDCOLUMNS(_tmpTable, "Rank", RANKX(_tmpTable, [SalesTotal], , DESC, Dense))
    RETURN
    MAXX(FILTER(_rankedTable, [Name] = SELECTEDVALUE(Table1[Name])), [Rank])

    Resulting in a visual like this:

     

    Kind regards

    Djerro123

    -------------------------------

    If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

    Keep those thumbs up coming! 🙂

    • Vish24's avatar
      Vish24
      Helper II

      JarroVGITThank you! Its working perfectly. I was making some typing mistake. Just need one more help. I want to show the rank in card after selecting name and year from slicer. Rank is coming 1 for all selected names. Its coming correctly in the table. Thank you!

      • JarroVGIT's avatar
        JarroVGIT
        Resident Rockstar
        Measure =
        VAR _tmpTable = SUMMARIZE(ALL(Table1), Table1[Name], Table1 [Year], "SalesTotal", SUM(Table1[Sales ]))
        VAR _rankedTable = ADDCOLUMNS(_tmpTable, "Rank", RANKX(_tmpTable, [SalesTotal], , DESC, Dense))
        RETURN
        MAXX(FILTER(_rankedTable, [Name] = SELECTEDVALUE(Table1[Name]), [Year] = SELECTEDVALUE(Table1[Year])), [Rank])

        That should work:)
    • Vish24's avatar
      Vish24
      Helper II

      JarroVGIT   I tried this and I am getting the error "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

      • JarroVGIT's avatar
        JarroVGIT
        Resident Rockstar

        Please show screenshot of the formula bar, are you getting any red didly lines?