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
vendersonalias0
Frequent Visitor

How to RANK by MAX date of each group without creating a second table?

My source data has a table with users and each sale they make is recorded as a row.

My goal is to find the latest date each user made a sale then rank those dates accordingly with the latest being 1.

 

Table Example

pbihelp.PNG

 

The formula I'm using to find the max date is working correctly

Max Date = CALCULATE(MAX('salestable'[Date]),ALLSELECTED('salestable'[Date]))
 
but my last sale measure is giving me the ranking relative to all dates rather than the max date of each group
my intended output should have:
rank 2 instead of rank 4,
rank 3 instead of rank 7 etc.
I believe it is ranking each group's max date vs all dates in the table instead of only the ranks by group.
 
Last Sale = RANKX(ALL('salestable'),[Max Date],,DESC,Dense)
 
I'm not sure if there is a better way to do this but the desired output is to have cards displaying the names of the last few users which made a sale. (In the real data, there are at most 2 sales / week)
My idea was to have a multi row card with all users filtered rank 1, the second card would be users filtered to rank 2 etc. up until 3-4. There is probably a better way to do this but this is what I came up with, any suggestions or improvements would be welcome too.
 
Thank you!
Happy Holidays!

 

 

1 ACCEPTED SOLUTION
vendersonalias0
Frequent Visitor

Thanks for the help guys, funny enough when I was creating a mock data set I happened to use ALLEXCEPT in the MAX DATE formula, then ALLSELECTED in the last date measure started to work... pbihelp.PNG

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @vendersonalias0 ,

You can create a measure as below:

Last Sale =
RANKX (
    ALLSELECTED ( 'salestable' ),
    CALCULATE ( MAX ( 'salestable'[Date] ) ),
    ,
    DESC,
    DENSE
)

Last sale.JPG

Best Regards

parry2k
Super User
Super User

@vendersonalias0 makes sense, I guess you used ALLEXCEPT ( Table, Table[User]), correct?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

vendersonalias0
Frequent Visitor

Thanks for the help guys, funny enough when I was creating a mock data set I happened to use ALLEXCEPT in the MAX DATE formula, then ALLSELECTED in the last date measure started to work... pbihelp.PNG

parry2k
Super User
Super User

@vendersonalias0 there are many ways to achieve this. I would recommend putting sample data in pbix and share thru one drive/google drive and will get you the solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

CNENFRNL
Community Champion
Community Champion

@vendersonalias0 , frankly speaking, the complexity of RANKX() is way beyond one's expectation, especially when you include another measure in it; context transition occur twice during the evaluation of RANKX.

Unless you paste some dummy data or a pbix file, it's hard to author a correct measure that fits in your scenario.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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
Top Kudoed Authors