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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Create Rank column based on grouping and order by another column

I need to create a calculated column which will contain a rank value but this will be based on multiple columns: The sample data is as below : I need to create a Rank column and its shoulbe grouped by statment_id and ordered by Line_id.

Example: For statement_id = 400, line_id 321 should get Rank 1, line_id = 303 should get Rank 2 For statement_id = 100, line_id 222 should get Rank 1, line_id = 221 should get Rank 2

Sample Data: 

statement_idline_idvalue_dateActv_Flag
4003215/15/2019Y
4003215/15/2019Y
4003035/13/2019Y
4003035/13/2019Y
1002224/9/2019Y
1002224/9/2019Y
1002214/9/2019Y
1002214/9/2019Y
1002024/1/2019Y
1002024/1/2019Y
6085534/10/2018Y
6085534/10/2018Y
6085526/26/2019Y
6085526/26/2019Y
6085516/26/2019Y
6085516/26/2019Y

 

Expected Result:

 

statement_idline_idvalue_dateActv_FlagRank
4003215/15/2019Y1
4003215/15/2019Y1
4003035/13/2019Y2
4003035/13/2019Y2
1002224/9/2019Y1
1002224/9/2019Y1
1002214/9/2019Y2
1002214/9/2019Y2
1002024/1/2019Y3
1002024/1/2019Y3
6085534/10/2018Y1
6085534/10/2018Y1
6085526/26/2019Y2
6085526/26/2019Y2
6085516/26/2019Y3
6085516/26/2019Y3

Thanks in advance 🙂

2 ACCEPTED SOLUTIONS
MFelix
Super User
Super User

Hi @Anonymous ,

 

Create the following calculated column to your table:

 

Rankin =
RANKX (
    FILTER ( 'Table'; 'Table'[statement_id] = EARLIER ( 'Table'[statement_id] ) );
    'Table'[line_id];
    ;
    DESC;
    DENSE
)

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

incase you wan to create a Calculated COlumn

 

 

 

RANKing Group = RANKX(FILTER('Table','Table'[statement_id] = EARLIER('Table'[statement_id])),'Table'[line_id],,DESC,DENSE)

 

 

 

1.jpg

 

 

Incase you want to create a measure

 

 

 

RANKing OrderId = RANKX(FILTER(ALL('Table'[statement_id],'Table'[line_id]), 'Table'[statement_id] = MAX('Table'[statement_id])),CALCULATE(SUM('Table'[line_id])))

 

 

 

 

1.jpg

 

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

View solution in original post

3 REPLIES 3
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

incase you wan to create a Calculated COlumn

 

 

 

RANKing Group = RANKX(FILTER('Table','Table'[statement_id] = EARLIER('Table'[statement_id])),'Table'[line_id],,DESC,DENSE)

 

 

 

1.jpg

 

 

Incase you want to create a measure

 

 

 

RANKing OrderId = RANKX(FILTER(ALL('Table'[statement_id],'Table'[line_id]), 'Table'[statement_id] = MAX('Table'[statement_id])),CALCULATE(SUM('Table'[line_id])))

 

 

 

 

1.jpg

 

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

Hello how about it, how could you apply the calculated column you showed, but for more than one parameter? That is, I apply a RANK but according to four other columns (for example in my case YEAR, QUARTER, AGGLOMERATE and INCOME, and not just a column like the detailed one.

I thank you in advance! I can't find this solution anywhere.

MFelix
Super User
Super User

Hi @Anonymous ,

 

Create the following calculated column to your table:

 

Rankin =
RANKX (
    FILTER ( 'Table'; 'Table'[statement_id] = EARLIER ( 'Table'[statement_id] ) );
    'Table'[line_id];
    ;
    DESC;
    DENSE
)

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors