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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
ScottTynan
Frequent Visitor

Urgent Help Needed - DAX Measure (or calculated column) to return the second to last invoice date

Hello, 

I have a data set of revenue by period which basically holds invoice data. Date, Customer, invoice item, $ etc. 

I need to show next to items that were invoiced this month what month(date) they were last invoiced for the same item to the same customer.

With the help of google I have created the below but it is returning the most recent date rather than the second to last. I also need it to ignore any filters on the report, visual or page which it is not doing currently.
Any Ideas?

Previous Invoice Date =
calculate(
lastdate('Revenue by Period'[Date])
,
filter(ALL('Revenue by Period'),
[Debtor Number]=selectedvalue('Revenue by Period'[Debtor Number]) &&
[Job Code]=selectedvalue('Revenue by Period'[Job Code])))
1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

Try something like this:

Data:

ValtteriN_0-1659360761871.png

ValtteriN_1-1659360860424.png

 

DAX:

LastInvoiced =
var cdate = MAX(LastInvoiced[I_date]) var _result =

 CALCULATE(MAX(LastInvoiced[I_date]),LastInvoiced[I_date]<cdate,ALL('LastInvoiced'[I_date])) return

 IF(ISBLANK(_result),"NA",_result)



End result:

ValtteriN_2-1659361587862.png

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/









Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
ValtteriN
Super User
Super User

Hi,

Try something like this:

Data:

ValtteriN_0-1659360761871.png

ValtteriN_1-1659360860424.png

 

DAX:

LastInvoiced =
var cdate = MAX(LastInvoiced[I_date]) var _result =

 CALCULATE(MAX(LastInvoiced[I_date]),LastInvoiced[I_date]<cdate,ALL('LastInvoiced'[I_date])) return

 IF(ISBLANK(_result),"NA",_result)



End result:

ValtteriN_2-1659361587862.png

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/









Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I'm absolutely bamboozled. 
That seems to have worked, How is it matching the customer and the job code without referencing them at all?

ScottTynan_0-1659364080127.png

 

Hi @ScottTynan ,

DAX notices row context so when you apply the column level filters the calculation takes these as filters and considers when was the last invoice date based on those values. I recommend reading this post about the matter to understand this interaction better: https://www.sqlbi.com/articles/row-context-in-dax/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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