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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
SC30GSWNBA
Frequent Visitor

DAX Function to create sales difference between two consecutive dates

Hello Everyone,

 

I am stuck in creating DAX function to create sales difference between two consecutive dates. I have a data in the following table shown below - 

As_of_DateSales
07-05-202534
07-05-202534
07-05-202534
08-05-202554
09-05-202523
09-05-202523
10-05-202556
10-05-202556
10-05-202556
10-05-202556
10-05-202556
13-05-202512
13-05-202513
13-05-202514
14-05-202523
14-05-202523
15-05-202545
16-05-202567
17-05-202589
17-05-202589
17-05-202589
17-05-202589
17-05-202589
17-05-202589
20-05-202512
20-05-202512
20-05-202512
21-05-202534
21-05-202534
22-05-202556
22-05-202556
22-05-202556
23-05-202578
24-05-202556
27-05-202598
27-05-202598
27-05-202598

 

I need to create a DAX measure to calculate daily total sales and a T-1 sales column to create sales difference between two consecutive days. 

SC30GSWNBA_1-1717471734421.png

Also there is no sales on weekends, so we need to take care of no sales on weekends while calculating the measure - Previous Day Sales

5 REPLIES 5
Ritaf1983
Super User
Super User

Hi @SC30GSWNBA  you can create 2 measures :

PreviousDateSales =
VAR CurrentDate = MAX('Sales table'[As_of_Date])
VAR PreviousDate = CALCULATE(MAX('Sales table'[As_of_Date]), 'Sales table'[As_of_Date] < CurrentDate)
RETURN
CALCULATE(SUM('Sales table'[Sales]), 'Sales table'[As_of_Date] = PreviousDate)
 
For Delta :
Delta = [sales_]-[PreviousDateSales]
Result :
Ritaf1983_0-1717554765403.png

PBIX is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

The PreviousDate VAR is returning me 31st Dec 2024. May be that's the reason why it is not working.

Hi @SC30GSWNBA  i see that all results are correct....

Did you download the pbix to follow thr steps?

If yes please show what is wrong

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Yes, I downloaded your file. I am connected to a database and when I apply MAX(Sales Data[Date]), it gives me 31st Dec 2024 as the output rather than the latest date. Not sure why that is happening.

Unfortunately, I can't determine the exact problem without access to your file.

There's an alternative method to access the value in the row above within a visualization context using the offset function.

Regrettably, I'm currently not at my computer and cannot provide an example. However, you can refer to the guide linked below:

https://youtu.be/C3QY0DWts8w?si=b5JhPQwq51lLw1tO

 

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors