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
lync0056
Helper I
Helper I

DAX - 2nd to last Date - FILTER Job Level

Hi all,

 

I'm having trouble returning the 2nd to last MAX invoice date inside DAX when I am filtering in Matrix by Client with drilldown to JobID. (Just for reverence, it is 1 Table - Invoices. All Invoices have a Client allocated to it and a JobID. So a Client can have many JobIDs)

 

The Last Date is no issue

Last Invoice Date = LASTDATE ( Invoices[Date] )
 
(Context is August 2019)
The second to last date works inside the context for only the Client filter. It is blank for JobIDs.
2nd To Last Invoice Date = CALCULATE( MAX( Invoices[Date]), FILTER( Invoices, Invoices[Date] <> MAX( Invoices[Date])))
 
Above will work if 2 Invoices were raised in August. It will give me the one previous for the Client. The moment I leave the August Context with either ALL or ALLSELECTED, it either returns blank, or the 31/08/2019. 
 
2nd To Last Invoice Date = CALCULATE( MAX( Invoices[Date]), FILTER( ALLSELECTED(Invoices), Invoices[Date] <> MAX( Invoices[Date])))
 
Any help would be appreciated.
 
 
Cam
 
1 ACCEPTED SOLUTION
lync0056
Helper I
Helper I

Went a SQL path to solve this.

View solution in original post

3 REPLIES 3
lync0056
Helper I
Helper I

Went a SQL path to solve this.

v-chuncz-msft
Community Support
Community Support

@lync0056 

 

It seems that you may change "<>" to "<".

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

@v-chuncz-msft 

This doesn't seem to work. In August context, looking at 1 particular JobID, it returns 30/08/2019

It should be returning 31/07/2019, as this was the last invoice raised for this Job. 30/08/2019 makes no sense, as no invoice was raised on this date for this job. 

 

DAX

2nd To Last Invoice Date = CALCULATE( MAX( Invoices[Date]),
FILTER( ALL(Invoices), Invoices[Date] < MAX(Invoices[Date]))
)
 

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.