Forum Discussion
Rolling up a SUM calculation
Hi all
I have a deceptively simple set of data, but trying to accomplish a calculation within a calculation and I've been stuck.
Essentially I have a number of lines per employee stating their project allocations and vacation / training time.
What I'm trying to calculate is the number of billable days per person on a given period (say per month).
Obviously during vacation / training time, employee is non-billable (let's assume those always take a full day).
To achieve my result, I need to check for each day in my date range whether the employee is billable, and if so add up billable time incurred by their various project allocations.
Maybe the issue is that I'm trying to do all that in a single measure 😅, but here's where I am:
- I've created a "Billable" column, which is basically = Allocation x (1 for projects OR -1 for other non-billable activities).
- then created a measure (below) which adds up Billable for each day for each activity row falling within my date range.
IF condition "weeds out" days when non-billable activity is superceding billable ones (thereby counting as a full non-billable day).
CheckSum =
VAR vDaily =
CALCULATE(
SUM( Table[Billable] ),
FILTER(
Table,
COUNTROWS(
FILTER(
VALUES( DATES[Date] ),
Table[Start] <= DATES[Date] && Table[End] >= DATES[Date]))
> 0))
RETURN
IF( vDaily > 0, vDaily, 0)
The measure works when tested for a single employee, but I cannot manage to roll it up for each employee in my roster.
Any ideas?
Thank you!
Hi Neeko
Your proposed measure doesn't work, however I've found wrapping up Checksum in a simple new measure with SUMX does the trick.
SUMX( DATESBETWEEN (DATES[Date], MIN(DATES[Date]), MAX(DATES[Date]) ), [CheckSum] )Thank you for your reply!
2 Replies
- AnonymousNot applicable
Hi trsh3r ,
Please try this measure.
CheckSum = VAR vDaily = CALCULATE( SUM( Table[Billable] ), FILTER( Table, COUNTROWS( FILTER( VALUES( DATES[Date] ), Table[employee]=MAX(Table[employee]) && Table[Start] <= DATES[Date] && Table[End] >= DATES[Date])) > 0)) RETURN IF( vDaily > 0, vDaily, 0)Best Regards,
Neeko Tang
If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.
- trsh3rFrequent Visitor
Hi Neeko
Your proposed measure doesn't work, however I've found wrapping up Checksum in a simple new measure with SUMX does the trick.
SUMX( DATESBETWEEN (DATES[Date], MIN(DATES[Date]), MAX(DATES[Date]) ), [CheckSum] )Thank you for your reply!