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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ruxandraalina
Helper I
Helper I

Rank categories with duplicate categories

Hello,

 

I am trying to rank the column Group Category by Start Date for each Incident Number. I've used the RANKX formula, but I don't get the result I need.

I need my rank to look like below:

ruxandraalina_0-1654761494538.png

Any help is appreciated!

Thank you!

3 REPLIES 3
tamerj1
Super User
Super User

Hi @ruxandraalina 
I don't think there is a simple solution for this. The problem is that you want the count to increase by 1 everytime the group category changes which is not  a conventional requirement. However, this is a sample file with the solution https://www.dropbox.com/t/bf4kLtD0RgWQpoWh

This requires creating two calculated columns (it can be done with one column but would be too complex to implement)

1.png

Rank = 
VAR IncidentTable = 
    CALCULATETABLE ( Incidents, ALLEXCEPT ( Incidents, Incidents[IncidentNumber] ) )
VAR IncidentCategoryTable = 
    CALCULATETABLE ( Incidents, ALLEXCEPT ( Incidents, Incidents[IncidentNumber], Incidents[Group Category] ) )
VAR UniqueDateTime = 
    Incidents[StartDate] + Incidents[EndDate_custom]
VAR Rank1 = 
    RANKX ( IncidentTable, Incidents[StartDate] + Incidents[EndDate_custom],, ASC ) 
VAR Rank2 =
    RANKX ( IncidentCategoryTable, Incidents[StartDate] + Incidents[EndDate_custom],, ASC ) 
RETURN
    Rank1 - Rank2

2.png

Group Category  Rank = 
VAR IncidentTable =
    CALCULATETABLE ( Incidents, ALLEXCEPT ( Incidents, Incidents[IncidentNumber] ) )
VAR UniqueDate = Incidents[StartDate] + Incidents[EndDate_custom]
VAR PrevuiousTable =
    FILTER ( IncidentTable, Incidents[StartDate] + Incidents[EndDate_custom] <= UniqueDate )
VAR Ranks = 
    SELECTCOLUMNS ( PrevuiousTable, "@Rank", Incidents[Rank] )
RETURN
    COUNTROWS ( DISTINCT ( Ranks ) )

Hello!

Thank you very much!

Unfortunately the second formula is simply not loading. I've tried on two different laptops, one with 8 GM RAM and another one with 16 and it's "working on it" for hours. I've tried restarting and refreshing everything multiple times, but with the same result. 

Anyway, thanks a lot! 

@ruxandraalina 

It is indeed heavy. I'm not sure if I can find another way to calculate this but I will try. I'll let you know if I was able to find something.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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