Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Zerozinho
New Member

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?

 

 

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

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])))

 

 

 

1.PNG

 

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)

View solution in original post

3 REPLIES 3
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"

 

 

 

image.png

harshnathani
Community Champion
Community Champion

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])))

 

 

 

1.PNG

 

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)

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?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors