Forum Discussion
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_Date | Sales |
| 07-05-2025 | 34 |
| 07-05-2025 | 34 |
| 07-05-2025 | 34 |
| 08-05-2025 | 54 |
| 09-05-2025 | 23 |
| 09-05-2025 | 23 |
| 10-05-2025 | 56 |
| 10-05-2025 | 56 |
| 10-05-2025 | 56 |
| 10-05-2025 | 56 |
| 10-05-2025 | 56 |
| 13-05-2025 | 12 |
| 13-05-2025 | 13 |
| 13-05-2025 | 14 |
| 14-05-2025 | 23 |
| 14-05-2025 | 23 |
| 15-05-2025 | 45 |
| 16-05-2025 | 67 |
| 17-05-2025 | 89 |
| 17-05-2025 | 89 |
| 17-05-2025 | 89 |
| 17-05-2025 | 89 |
| 17-05-2025 | 89 |
| 17-05-2025 | 89 |
| 20-05-2025 | 12 |
| 20-05-2025 | 12 |
| 20-05-2025 | 12 |
| 21-05-2025 | 34 |
| 21-05-2025 | 34 |
| 22-05-2025 | 56 |
| 22-05-2025 | 56 |
| 22-05-2025 | 56 |
| 23-05-2025 | 78 |
| 24-05-2025 | 56 |
| 27-05-2025 | 98 |
| 27-05-2025 | 98 |
| 27-05-2025 | 98 |
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.
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
- Ritaf1983Super 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)RETURNCALCULATE(SUM('Sales table'[Sales]), 'Sales table'[As_of_Date] = PreviousDate)For Delta :Delta = [sales_]-[PreviousDateSales]Result :PBIX is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
- SC30GSWNBAFrequent Visitor
The PreviousDate VAR is returning me 31st Dec 2024. May be that's the reason why it is not working.
- Ritaf1983Super User
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