Forum Discussion

Zerozinho's avatar
Zerozinho
New Member
5 years ago
Solved

How do I rank inside many segments?

Hey, I'm not experienced with PowerBI and I'm failing to rank the following data:

 

NameGroupSegmentValueRankMax Rank
Jorge

1

Small

9

11
Jorge1Medium912

Gabriel

1Medium822
Maria2Small

4

33
Maria2Medium411
Maria2Big511
Carlos2Small623
Anthony2Small713
Louis3Big311

 

So, what I want to do is rank those values according to their Group and Segment (column Rank). I also would like to set another column with the number of contestants in each Group-Segment, set as "Max Rank".

 

I've tried using the RANKX function but I got no luck. Could someone can light me a solution for this problem, please?

 

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Zerozinho ,

     

    You can use this DAX expression to Rank groups and segments.

     

     

    Ranki = RANKX(FILTER(ALL('Table'),'Table'[Segment] = MAX ('Table'[Segment]) && 'Table'[Group] = MAX ('Table'[Group])),CALCULATE(Sum('Table'[Value])))

     

     

     

     

    For MAX Rank you can use the following DAX

     

    Counti = COUNTX(FILTER(ALL('Table'),'Table'[Segment] = MAX ('Table'[Segment]) && 'Table'[Group] = MAX ('Table'[Group])),CALCULATE(Sum('Table'[Value])))

     

    Regards,
    Harsh Nathani
    Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Zerozinho ,

     

    You can use this DAX expression to Rank groups and segments.

     

     

    Ranki = RANKX(FILTER(ALL('Table'),'Table'[Segment] = MAX ('Table'[Segment]) && 'Table'[Group] = MAX ('Table'[Group])),CALCULATE(Sum('Table'[Value])))

     

     

     

     

    For MAX Rank you can use the following DAX

     

    Counti = COUNTX(FILTER(ALL('Table'),'Table'[Segment] = MAX ('Table'[Segment]) && 'Table'[Group] = MAX ('Table'[Group])),CALCULATE(Sum('Table'[Value])))

     

    Regards,
    Harsh Nathani
    Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

    • Zerozinho's avatar
      Zerozinho
      New Member

      Thank you very much! It worked just fine!

       

      Another question, do you have any idea of how to do the column "Max Rank", that just collect the number of rows in each "peer group" and set it as the Max Rank column in my example?

  • Anonymous's avatar
    Anonymous
    Not applicable

     

    let
        Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sovSk9V0lEyBOLg3MScHCBtCeUbKsXqoKrwTU3JLM1FUmIEVuKemFSUmZqDrsgCrACmyDexKDMRKgKzyQSIjcEYXQXcEBMUxyArccpMB5KmKPLOiUU5+cVotphB+RBbHPNKMvLzKtHUmEONgajxyS/NLIa6DWKNMcKaWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Group = _t, Segment = _t, Value = _t, Rank = _t, #"Max Rank" = _t]),
        #"Raggruppate righe" = Table.Group(Origine, {"Group", "Segment"}, {{"MaxRankCalc", each List.Max([Rank]), type nullable text}}),
        #"Merge di query eseguito" = Table.NestedJoin(Origine, {"Group", "Segment"},  #"Raggruppate righe", {"Group", "Segment"}, "hhh"),
        #"Tabella hhh espansa" = Table.ExpandTableColumn(#"Merge di query eseguito", "hhh", {"MaxRankCalc"}, {"MaxRankCalc"})
    in
        #"Tabella hhh espansa"