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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
TeJai
Frequent Visitor

Last day of sale before a specific date

Hey,

 

I am struggling writing a specific formula for finding the last day of sale before i specific date - and not just the last sales date, as i wish to track "idle" inventory development over time.

 

I have two tables, one with transactions and one with end of month inventory value. I need to write a new column in the financial stock value tabel which specifies the latest day of sale for a product prior to the end of month inventory date (date column in financial stock value tabel).

 

The dates should be extracted from the transaction tabel, date column (for sales entries), and written in the financial stock value tabel, last sale day column. Color coding shows expected output. 

 

Excel tables attached below as well. 

 

Any help is appreciated as this challenge is beyond my DAX knowledge. 

 

TeJai_0-1707576277121.png

 

 

 

Transaction table  
ProductDateTypevalue
A14-05-2023Sales2
A16-05-2023Purchase-2
A27-06-2023Sales2
B16-05-2023Sales1
B16-06-2023Sales1
B27-07-2023Sales1
C14-05-2023Purchase-3
C16-05-2023Sales3
C27-06-2023Sales3

 

Financial Stock value tabel  
Product DateStock valueLast sale dayDays since last sale
A31-05-202310014-05-202317
B30-06-202312027-06-20233
C31-07-20239027-06-202334
A31-05-202310016-05-202315
B30-06-202312016-06-202314
C31-07-20239027-07-20234
A31-05-202310016-05-202315
B30-06-202312027-06-20233
C31-07-20239027-06-202334
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula

Last sale date = CALCULATE(MAX('Transaction'[Date]),FILTER('Transaction','Transaction'[Product]=EARLIER('Financial stock value'[Product ])&&'Transaction'[Type]="Sales"&&'Transaction'[Date]<=EARLIER('Financial stock value'[Date])))

Hope this helps.

Ashish_Mathur_0-1707611269292.png

 


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

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula

Last sale date = CALCULATE(MAX('Transaction'[Date]),FILTER('Transaction','Transaction'[Product]=EARLIER('Financial stock value'[Product ])&&'Transaction'[Type]="Sales"&&'Transaction'[Date]<=EARLIER('Financial stock value'[Date])))

Hope this helps.

Ashish_Mathur_0-1707611269292.png

 


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

Hi Ashish_Mathur,

 

Thanks, simple solution working perfectly - and helped me figure out why my approach based on ISONORAFTER wasn't fit for this issue. 

 

Sincerely,

You are welcome.


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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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