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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

DAX

I have to pick the second max date associated territory for particular policy number from the multiple records

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try

Last Date = CALCULATE ( MAx ( territory [Date] ), ALLEXCEPT ( territory , territory [policy number] ) )

second max date  = 
VAR __LAST = [First Purchase] 
RETURN CALCULATE ( MIN ( territory[Date] ), ALLEXCEPT ( territory , territory [policy number] ), Dates[Date] < __LAST )

 

Or have Rank and filter for 2

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

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Share a dataset and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

@Anonymous 

Try create the following column: 

 

Column = Calculate(Max(Table[Date), Filter(Table, Table[Date]<Max(Table[Date])), Allexcept(Table, Table[Police Number]))

 

 

Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you This is also working for finding the second max value but not associated value.

Thank you for your help😊

amitchandak
Super User
Super User

@Anonymous , Try

Last Date = CALCULATE ( MAx ( territory [Date] ), ALLEXCEPT ( territory , territory [policy number] ) )

second max date  = 
VAR __LAST = [First Purchase] 
RETURN CALCULATE ( MIN ( territory[Date] ), ALLEXCEPT ( territory , territory [policy number] ), Dates[Date] < __LAST )

 

Or have Rank and filter for 2

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
Anonymous
Not applicable

Thank you I have modified the query as per my data it  is working fine.

Thank you so much

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.