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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
Anonymous
Not applicable

Ranks by Category

Dear All, I have a data as below and i would like to calculate the ranks based on RNO_Condition.

Data:-

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc07CoUwEEDRrTymlpCZ/LC0faAWlhKCYEBBYooUunsTVLC9p7jjCCiMNC74HSoQSJwpAlu9vU9L7sgFVwzFB4a4hmkrVhtG6haJWrluT792itHPRUkzTR9twrH6dGYiw58uEd0/lX++SLD2Ag==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [RNO_Condition = _t, Amt = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RNO_Condition", type text}, {"Amt", type number}})
in
    #"Changed Type"

 

 

I have written below dax and based on that i am getting the below shown output

 

MohanV_0-1602696891276.png

But i am expecting the ranking as below image.

 

MohanV_1-1602696940899.png

 

Any help please.

Thanks,

Mohan V.

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hi, @Anonymous , as you want to rank the entries within a sub-group, I'd suggest adding a column, whether in PQ or by calculated column, to distinguish different sub-group.

 

#"Extract Prefix" = Table.AddColumn(#"Changed Type", "Category", each Text.Start([RNO_Condition], 5))

 

or using calculated column Screenshot 2020-10-14 201905.png

The measure is

 

Ranks = 
VAR __cat = MAX ( 'Dataset'[Category] )
RETURN
    RANKX (
        FILTER ( ALL ( 'Dataset' ), 'Dataset'[Category] = __cat ),
        CALCULATE ( MAX ( 'Dataset'[Amt] ) )
    )

 

Screenshot 2020-10-14 202337.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

Hi, @Anonymous , as you want to rank the entries within a sub-group, I'd suggest adding a column, whether in PQ or by calculated column, to distinguish different sub-group.

 

#"Extract Prefix" = Table.AddColumn(#"Changed Type", "Category", each Text.Start([RNO_Condition], 5))

 

or using calculated column Screenshot 2020-10-14 201905.png

The measure is

 

Ranks = 
VAR __cat = MAX ( 'Dataset'[Category] )
RETURN
    RANKX (
        FILTER ( ALL ( 'Dataset' ), 'Dataset'[Category] = __cat ),
        CALCULATE ( MAX ( 'Dataset'[Amt] ) )
    )

 

Screenshot 2020-10-14 202337.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Megha166
Microsoft Employee
Microsoft Employee

Is your calculation creating groups first on the basis of the Prefix Number in RNO_Condition and then ranking on basis of Amt?

@Anonymous Check this.

https://community.powerbi.com/t5/Desktop/DAX-Ranking-within-a-group/td-p/261079

 

Let me know if you still needs help. I will write the DAX Expression for you.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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