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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
kasiaw29
Resolver II
Resolver II

How to find max, second, third latest date after max.

Hi there,

 

Wondering if anyone has attempted this before. I'm trying to find max date per group, second max date and then third. 

I'm okay with getting max and second to that by using the following: 

 

The calculation to find max date per group: 

Latest Date = CALCULATE(
                                      MAX('Table'[Date]),  ALLEXCEPT('Table','Table'[ID]))
The calculation to find a second latest date: 
2nd Latest Date =CALCULATE
                                     (MAX('Table'[Date]), ALLEXCEPT('Table','Table'[ID]),
                                                'Table'[Date] <> 'Table'[Latest Date])
 
Is there a way to find 3rd latest date? 
 
Thanks! 
1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @kasiaw29 ,

 

if that worked, then you can just repeat it:

3rd Latest Date =
CALCULATE(
    MAX( 'Table'[Date] ),
    ALLEXCEPT( 'Table', 'Table'[ID] ),
    'Table'[Date] <> [Latest Date] && 'Table'[Date] <> [2nd Latest Date]
)
If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@kasiaw29 I'm thinking that you should do something like:

Measure = 
    VAR __Table = ADDCOLUMNS('Query1',"__Rank",RANKX('Query1',[Date],,DESC))
RETURN
    MAXX(FILTER(__Table,[__Rank] = 3),[Date])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
selimovd
Super User
Super User

Hey @kasiaw29 ,

 

if that worked, then you can just repeat it:

3rd Latest Date =
CALCULATE(
    MAX( 'Table'[Date] ),
    ALLEXCEPT( 'Table', 'Table'[ID] ),
    'Table'[Date] <> [Latest Date] && 'Table'[Date] <> [2nd Latest Date]
)
If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

Should have thought of that! Magic, worked perfectly! 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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