Forum Discussion
Rollover Hours Calculation
I need some help with a DAX formula that can capture the balance of rollover hours per day. Example data below is below.
On the first day 10 hours of work was assigned but only 5 hours were completed, resulting in a 5 hour balance. The next day 20 hours of additional work was assigned and 10 hours were completed, which results in 10 hours for that day plus 5 from the previous day. I'm looking for a DAX formula that would do this calculation in the Rollover Balance column. I believe I need to use the EARLIER function but I cant seem to get it right.
Any help is greatly appreciated!
- Anonymous4 years ago
Hi Daxtothemax ,
You can try this code to create a calculated column by EARLIER() function.
Rollover Balance = CALCULATE ( SUM ( 'Table'[Daily Hours of Work] ) - SUM ( 'Table'[Daily Hours Completed] ), FILTER ( 'Table', 'Table'[Date] <= EARLIER ( 'Table'[Date] ) ) )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- amitchandakSuper User
Daxtothemax , You need to calculate Cumulative measure
Calculate(Sum(Table[Daily Work Hours]) - Sum(Table[Daily Hours completed]) , filter( allselected(Table), Table[Date]<= Max(Table[Date]) ) )
or
with date table
Calculate(Sum(Table[Daily Work Hours]) - Sum(Table[Daily Hours completed]) , filter( allselected(Date), Date[Date]<= Max(Date[Date]) ) )
- Ashish_MathurSuper User
Hi,
- Create a Calendar Table
- Build a relationship between the Date column of your Data Table to the Date column of your Calendar Table
- To your Table visual, drag Date from the Calendar Table
- Write these measures
- Daily hours of work = sum(Data[daily hours])
- Daily hours of work till date = calculate([Daily hours of work],datesytd(calendar[Date],"31/12))
- Daily hours completed = sum(Data[hours completed])
- Daily hours completed till date = calculate([Daily hours completed],datesytd(calendar[Date],"31/12))
- Rollover balance = [Daily hours of work till date]-[Daily hours completed till date]
Hope this helps.
- AnonymousNot applicable
Hi Daxtothemax ,
You can try this code to create a calculated column by EARLIER() function.
Rollover Balance = CALCULATE ( SUM ( 'Table'[Daily Hours of Work] ) - SUM ( 'Table'[Daily Hours Completed] ), FILTER ( 'Table', 'Table'[Date] <= EARLIER ( 'Table'[Date] ) ) )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.