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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.