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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

RANKX by Date and Multiple Categories (PBIX inside)

Hi!

 

I want to be able to RANKX by Date and 2 more columns.

So far with 1 column it works, for that I use the following measure:

 

 

RANK Room_Date = 
RANKX(
    FILTER('FACT Rooms', 'FACT Rooms'[RoomID] = EARLIER('FACT Rooms'[RoomID])),
    [Date],,ASC,Dense)

 

 

However I want to adapt this to a measure that also takes into account for the `Status`, as shown in the Dataset below, the last column 'RANK Room_Date_Status'. As you can see it starts from 1 again when it shifts from Empty to Full or the other way around.

 

RoomIDStatusFromDateToDateDaysDateDiff (ToDate - Date)DatumRANK Room_DateRANK Room_Date_Status
1Empty1/1/20201/10/20201071/3/202033
1Empty1/1/20201/10/20201061/4/202044
1Empty1/1/20201/10/20201051/5/202055
1Empty1/1/20201/10/20201041/6/202066
1Empty1/1/20201/10/20201031/7/202077
2Full1/1/20201/4/2020411/3/202033
2Full1/1/20201/4/2020401/4/202044
2Empty1/5/20201/6/2020211/5/202051
2Empty1/5/20201/6/2020201/6/202062
2Full1/7/20201/10/2020431/7/202071
3Full1/1/20201/5/2020521/3/202033
3Full1/1/20201/5/2020511/4/202044
3Full1/1/20201/5/2020501/5/202055

 

TestFile.pbix 

 

Any suggestions how to do this?

 

Kind regards,

Igor

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the quick response, those links are very valuable and made me easily understand what I needed to adapt.

 

I made the following calculated column which actually does the trick. I could of course simply add more statements in my FILTER statement.

 

RANK Room_Date_Status = 
RANKX(
    FILTER(
        'FACT Rooms', 
        'FACT Rooms'[RoomID]    = EARLIER('FACT Rooms'[RoomID]) && 
        'FACT Rooms'[Status]    = EARLIER('FACT Rooms'[Status]) && 
        'FACT Rooms'[FromDate]  = EARLIER('FACT Rooms'[FromDate])
    ),
    [Date],,ASC,Dense)

 

The MAX date is simply used so I can show the daycount in a Matrix visualization. I doesn't allow for a calculated column as value, so I simply put a MAX or MIN around it. I don't use that one anywhere else but the visualization.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks for the quick response, those links are very valuable and made me easily understand what I needed to adapt.

 

I made the following calculated column which actually does the trick. I could of course simply add more statements in my FILTER statement.

 

RANK Room_Date_Status = 
RANKX(
    FILTER(
        'FACT Rooms', 
        'FACT Rooms'[RoomID]    = EARLIER('FACT Rooms'[RoomID]) && 
        'FACT Rooms'[Status]    = EARLIER('FACT Rooms'[Status]) && 
        'FACT Rooms'[FromDate]  = EARLIER('FACT Rooms'[FromDate])
    ),
    [Date],,ASC,Dense)

 

The MAX date is simply used so I can show the daycount in a Matrix visualization. I doesn't allow for a calculated column as value, so I simply put a MAX or MIN around it. I don't use that one anywhere else but the visualization.

amitchandak
Super User
Super User

A rank measure can only be created on Measure. As taking max of date will reduce it one, that is not possible.

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.