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
ajaybabuinturi
Memorable Member
Memorable Member

Need to Create a Rank by using Calculated Column

Hello,

I got a tricky requirement to create a Rank by using Calculated column based on Category and Opportunity columns. How I need to create is, create a Rank based on individually categorey(A, B & C) and skip balnks from those RANK column. I added a snippet with existing columns and expected results. 

ajaybabuinturi_0-1761970747717.png

Thanks,

Ajay 

 

1 ACCEPTED SOLUTION
muhammad_786_1
Super User
Super User

Hello @ajaybabuinturi 

 

Please see, if this is what you want.

 

You can add an Index column using Power Query:
Go to Add Column tab → Index Column → select From 1

 

Then go to the Modeling tab and create a calculated column using the following DAX to get your desired output:

 

Rank =
IF(
NOT ISBLANK('Categories'[Opportunity]),
RANKX(
FILTER(
'Categories',
'Categories'[Category] = EARLIER('Categories'[Category])
&& NOT ISBLANK('Categories'[Opportunity])
),
'Categories'[Opportunity] + ('Categories'[Index] * 0.00001),
,
ASC,
SKIP
)
)

Img_Rank.JPG

 

Best Regards,
Muhammad Yousaf

 

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

LinkedIn

View solution in original post

5 REPLIES 5
v-aatheeque
Community Support
Community Support

Hi @ajaybabuinturi 

Have you had a chance to look through the responses shared earlier? If anything is still unclear, we’ll be happy to provide additional support.

Hi @ajaybabuinturi 

Just checking in to see if the previous response helped resolve your issue. If not, feel free to share your questions and we’ll be glad to assist.

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Opportunity", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Category"}, {{"Count", each Table.AddRankColumn(_, "Rank",    {"Opportunity", Order.Ascending},[RankKind = RankKind.Ordinal])},{"Nulls", each List.Count(_[Opportunity])-List.NonNullCount(_[Opportunity])}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Opportunity", "Index", "Rank"}, {"Opportunity", "Index", "Rank"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Count",{{"Index", Order.Ascending}}),
    #"Added Custom" = Table.AddColumn(#"Sorted Rows", "RRank", each if [Opportunity]=null then null else [Rank]-[Nulls])[[Category],[Opportunity],[Rank]],
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Category", type text}, {"Opportunity", Int64.Type}, {"Rank", Int64.Type}})
in
    #"Changed Type1"

Hope this helps.

Ashish_Mathur_0-1762041174793.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
muhammad_786_1
Super User
Super User

Hello @ajaybabuinturi 

 

Please see, if this is what you want.

 

You can add an Index column using Power Query:
Go to Add Column tab → Index Column → select From 1

 

Then go to the Modeling tab and create a calculated column using the following DAX to get your desired output:

 

Rank =
IF(
NOT ISBLANK('Categories'[Opportunity]),
RANKX(
FILTER(
'Categories',
'Categories'[Category] = EARLIER('Categories'[Category])
&& NOT ISBLANK('Categories'[Opportunity])
),
'Categories'[Opportunity] + ('Categories'[Index] * 0.00001),
,
ASC,
SKIP
)
)

Img_Rank.JPG

 

Best Regards,
Muhammad Yousaf

 

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

LinkedIn

ribisht17
Super User
Super User

Did not get the logic of ranking here.

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