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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Rank Dates within a Category or Group - DAX or Power Query

Hi,

 

I'm looking to rank my data to find the most recent information for each category.

 

Here's a brief example of the data I'm working with:

 

01.PNG

 

I have a Category column, a Date column and a Value column - the value column is irrelevant for what I want to achieve but I've included it so you can see where there are duplicate dates for the same Category. I don't need the Value column to be sorted or included in the Ranking.

 

This is what I'm looking to achieve:

 

02.PNG

 

I want the most recent Date for each Category to have the lowest number. If there are multiple instances of the same date they should all get the same rank. Then the date after this should get the next sequential number so there are no gaps - 1, 2, 3, etc. I'm looking for suggestions in either DAX or Power Query.

 

Can anyone help?

 

Thanks,

MarkJames

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

 @Anonymous

 

As a calculated column with DAX

 

RANK=RANKX(fILTER(Table1,[Category]=EARLIER([Category])),[Date],,DESC,dENSE)

Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

 @Anonymous

 

As a calculated column with DAX

 

RANK=RANKX(fILTER(Table1,[Category]=EARLIER([Category])),[Date],,DESC,dENSE)

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Hi Zubair,
Can you please advise how we can make this rank dynamic, meaning it will auto populate based on date range selected. Right now, even if you filter a later date out, it will still show the same rank.

Hi, what if you get a D category in one of the later dates and want to rank it accordingly to that date rank in the other categories?

 

BR

Anonymous
Not applicable

This is exactly what I was looking for. Thanks @Zubair_Muhammad

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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