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
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
- rocky098 years agoSolution Sage
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
- rocky098 years agoSolution Sage
actually, i found the reason,
My Date is changing once loading to data model. Actually, the time is early monring. Is it possible to prevent?
example: from 01-12-2017 01:50 to 01-12-2017 PM 01:50
- rivastoday7 years agoFrequent Visitor
I got the same error, could you solve it ?
- Anonymous8 years agoNot applicable
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
- Anonymous7 years agoNot applicable
I am getting the following error. Any idea how to fix it?
"An argument of function 'TIME' has the wrong data type or the result is too large or too small."
- rocky097 years agoSolution Sage
Did you checked your data type of Date Column in query editor?
- Anonymous7 years agoNot applicable
I tried this solution for the data in SQL server database. I am also getting the same error:
"An argument of function 'TIME' has the wrong data type or the result is too large or too small."
Can some one please help me to replve this
KKMUrthy
- rocky097 years agoSolution Sage
Please check your Data Type for the Date Column. It should be Date format.
- Anonymous7 years agoNot applicable
Anonymous
I was looking at your code, and I think it is probably going to be pretty useful for what I'm doing.
I was wondering if it would be possible to consider more than one "range" of working hours (I want to take out the lunch time) without having to create multiple columns and then adding them, just to make the code cleaner.
In my case, the time range would be like:
- 8:00 - 12:00
- 13:00 - 17:15
Thank you in advance!
- Anonymous7 years agoNot applicable
Hi
I am also getting the "The start date in Calendar function can not be later than the end date" error
but when I change my workiung hours this way, as in the code section I do not get the error BUT obviously have 0's as that is not working time
SELECTCOLUMNS ( GENERATESERIES (17,6 ), "Hour", [Value] )