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
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
I ensure the data type as Datetime in query editor. I then changed the datetime format to the one shown in the screenshot