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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
SimpleChemist
Frequent Visitor

Daily Difference

Good day!

I have a bit of a problem that I feel should be simple but is stumping me:

 
DateItemCumulative SalesDaily Sales
2025-05-05A305
2025-05-05B41
2025-05-05C153
2025-05-04A2510
2025-05-04B31
2025-05-04C122
2025-05-03A15 
2025-05-03B2 
2025-05-03C10 
 

 

I am trying to calculate the Daily Sales column, which looks at difference per day of each item. I have attempted calculate(max(cumulative sales),dateadd(date,-1,day)), as well as iterations with previousday, allexcept, etc. Any guidance would be splendid!

1 ACCEPTED SOLUTION

This was actually quite close! (Had never used Coalesce before so that was interesting).  Actually found a workaround after posting listed below:

 

DailyDiff =
var _Date = '[DATE]
var _Cav = '[ID]
var _LastDate = calculate(max([Date]),[ID]=_Cav,[Date]<_Date,all('TABLE'))
return
'[SALES] - CALCULATE(max([SALES]),'[ID]=_Cav,'[DATE]=_LastDate,all('TABLE'))

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @SimpleChemist ,

 

You can achieve your required output in the following manner: Use a calendar table related to your fact table and subtract yesterday’s cumulative value from today’s within the same item context.

Daily Sales :=
VAR TodayVal =
    MAX ( Sales[Cumulative Sales] )
VAR YesterdayVal =
    CALCULATE (
        MAX ( Sales[Cumulative Sales] ),
        DATEADD ( 'Date'[Date], -1, DAY )
    )
RETURN
TodayVal - COALESCE ( YesterdayVal, 0 )

DATEADD shifts the calendar back one day while the existing filter keeps the same item, giving the daily increment.

 

Best regards,

This was actually quite close! (Had never used Coalesce before so that was interesting).  Actually found a workaround after posting listed below:

 

DailyDiff =
var _Date = '[DATE]
var _Cav = '[ID]
var _LastDate = calculate(max([Date]),[ID]=_Cav,[Date]<_Date,all('TABLE'))
return
'[SALES] - CALCULATE(max([SALES]),'[ID]=_Cav,'[DATE]=_LastDate,all('TABLE'))

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.