Forum Discussion
Calculating Working hours
- Anonymous8 years ago
HI rocky09,
You can try to use below calculated column formula to calculate valid working hour:
Work Hour = VAR filtered = FILTER ( ADDCOLUMNS ( CROSSJOIN ( CALENDAR ( [ACTIVITY_DATE], [LASTMODIFIEDDATE] ), SELECTCOLUMNS ( GENERATESERIES ( 9, 18 ), "Hour", [Value] ) ), "Day of week", WEEKDAY ( [Date], 2 ) ), [Day of week] < 6 && [TicketID] = EARLIER ( Table1[TicketID] ) ) VAR hourcount = COUNTROWS ( FILTER ( filtered, ( [Date] >= DATEVALUE ( [ACTIVITY_DATE] ) && [Hour] > HOUR ( [ACTIVITY_DATE] ) + 1 ) && ( [Date] <= DATEVALUE ( [LASTMODIFIEDDATE] ) && [Hour] > HOUR ( [LASTMODIFIEDDATE] ) - 1 ) ) ) VAR remained = DATEDIFF ( TIMEVALUE ( [ACTIVITY_DATE] ), TIME ( HOUR ( [ACTIVITY_DATE] ) + 1, 0, 0 ), MINUTE ) + DATEDIFF ( TIME ( HOUR ( [LASTMODIFIEDDATE] ) - 1, 0, 0 ), TIMEVALUE ( [LASTMODIFIEDDATE] ), MINUTE ) RETURN IF ( hourcount <> BLANK (), (hourcount*60 + remained)/60, 0 )Regards,
Xiaoxin Sheng
Anonymous
Thank you so much sir.
I am getting the below error.
The Start date in Calendar function can not be later thanthe end date.
I guess, the first column may have greater date than modified date. Is there a way to dealth it
Hi rocky09,
>>I guess, the first column may have greater date than modified date. Is there a way to dealth it
It means your table contains records which start date greater than end date. Datediff function not support calculated with records who have greater startdate(compare with end date).
You can add some conditions to ignore calculation when 'start date' greater than 'end date'.
Notice: DATEDIFF(start date, end date, unit)
Regards,
Xiaoxin Sheng
- mpalha048 years agoHelper III
Hi,
I tried the formula above and I get the error message "The start date or end date in Calendar function can not be Blank value". Any way to resolve this?
Thanks
- omarevp7 years agoHelper II
Hi Anonymous I got a question for you:
I have 2 issues when I use your solution.
1. Error because those fields in calendar can not be blank.
2. Error because sometimes the lastdate is previous to firstdate.
Can you PLEASE give me some solution? I know those are conditions I have to add in the same code you put. But I don't know where to make it work.
Thanks man! I hope you to be fine.