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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
joshua1990
Post Prodigy
Post Prodigy

Ranking calculated column for group and subgroup for each week

I have a table with this structure

Year-WeekGroupSubgroupValueRanking (New)
2022-01AA112
2022-01AA212
2022-01BB151
2022-01BB251
2022-02AA151
2022-02BB132

 

Now I would like to add a column that shows me the rank for each week and for each group.

The result would be the last column.

How can this be done?

1 ACCEPTED SOLUTION

Hi,

Please try the below for creating a new column.

 

Ranking CC = 
VAR currentweek = Data[Year-Week]
VAR subgrouptable =
    SUMMARIZE (
        FILTER ( Data, Data[Year-Week] = currentweek && Data[Value] <> 0 ),
        Data[Subgroup],
        Data[Value]
    )
RETURN
IF( Data[Value] = 0, BLANK(),
    RANKX ( subgrouptable, Data[Value],, DESC, DENSE )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

7 REPLIES 7
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Picture1.png

 

Ranking CC =
VAR currentweek = Data[Year-Week]
VAR subgrouptable =
    SUMMARIZE (
        FILTER ( Data, Data[Year-Week] = currentweek ),
        Data[Subgroup],
        Data[Value]
    )
RETURN
    RANKX ( subgrouptable, Data[Value],, DESC, DENSE )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

@Jihwan_Kim Thanks a lot! That works perfectly well. Is there any chance to exclude all rows where [Value] = 0 ?

So the RANK stops when row has 0 as a value.

Hi,

Thank you for your feedback.

Could you please share the sample data, and then I can try to come up with more accurate solution.

Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

@Jihwan_Kim  THanks a lot!

Please find below sample data:

Year-WeekGroupSubgroupValueRanking (New)
2022-01AA112
2022-01AA212
2022-01BB151
2022-01BB251
2022-02AA151
2022-02BB132
2022BB20 

 

As you can see the last row has a 0 value. This should be excluded in the function.

Hi,

Please try the below for creating a new column.

 

Ranking CC = 
VAR currentweek = Data[Year-Week]
VAR subgrouptable =
    SUMMARIZE (
        FILTER ( Data, Data[Year-Week] = currentweek && Data[Value] <> 0 ),
        Data[Subgroup],
        Data[Value]
    )
RETURN
IF( Data[Value] = 0, BLANK(),
    RANKX ( subgrouptable, Data[Value],, DESC, DENSE )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you for that solution. And the version removing blanks is great.

 

amitchandak
Super User
Super User

@joshua1990 , Can explain logic , I tried a few combinations not able to get the same output

 

Column = rankx('Rank Table (2)',CALCULATE(sum([Value]), filter('Rank Table (2)', [Group] =EARLIER('Rank Table (2)'[Group]) && 'Rank Table (2)'[Subgroup] =max('Rank Table (2)'[Subgroup]) )),,DESC,Dense)
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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