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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.