Forum Discussion
measure date difference power excluding weekend
- 8 years ago
Hi shado26,
How to override it? The formula in my last post will show up "Error" in the column.
ifmet = VAR sla2 = DATEDIFF ( DUMP_DATA_FROM_PURCHASE[start], DUMP_DATA_FROM_PURCHASE[end], SECOND ) RETURN IF ( WEEKDAY ( DUMP_DATA_FROM_PURCHASE[start],2 ) IN { 5, 6 }, "Week End approval", IF ( TIMEVALUE ( DUMP_DATA_FROM_PURCHASE[start] ) < TIME ( 9, 0, 0 ) || TIMEVALUE ( DUMP_DATA_FROM_PURCHASE[end] ) > TIME ( 18, 0, 0 ), "done", IF ( sla2 < 0,"Error",if(sla2 <= 5400, "Met", "Failed" ) ) ))Best Regards,
Dale
- 8 years ago
hi dale
SLA mean service level agreement
our stranded SLA are 1h 30 min to process orders
so if i received any order i need to process it within 1h 30 min
so i need formula to calculate received time " DateTimeFrom" and approved time " DateTimeTo" and to exclude week and working hours
Ex i approved this with 18 Min
Hi shado26,
Please try out a calculated column like this. You can download a demo here.
ifmet =
VAR sla2 =
DATEDIFF ( [Start], [End], SECOND )
RETURN
IF (
WEEKDAY ( [Start], 2 ) IN { 5, 6 },
"NA",
IF (
TIMEVALUE ( [Start] ) < TIME ( 8, 0, 0 )
|| TIMEVALUE ( [End] ) > TIME ( 17, 0, 0 ),
"NA2",
IF ( sla2 <= 5400, "Met", "Failed" )
)
)Notes:
All the signs can be changed.
NA: weekends.
NA2: either start or end is out of work hour.
Best Regards,
Dale
- v-jiascu-msft8 years agoMicrosoft Employee
Hi shado26,
I hope your data isn't classified. Do you mean there are time intervals smaller than 0? They are from your original data. I changed the formula to find them out. How do you want to deal with them?
ifmet = VAR sla2 = DATEDIFF ( DUMP_DATA_FROM_PURCHASE[start], DUMP_DATA_FROM_PURCHASE[end], SECOND ) RETURN IF ( WEEKDAY ( DUMP_DATA_FROM_PURCHASE[start],2 ) IN { 5, 6 }, "Week End approval", IF ( TIMEVALUE ( DUMP_DATA_FROM_PURCHASE[start] ) < TIME ( 9, 0, 0 ) || TIMEVALUE ( DUMP_DATA_FROM_PURCHASE[end] ) > TIME ( 18, 0, 0 ), "done", IF ( sla2 < 0,"Error",if(sla2 <= 5400, "Met", "Failed" ) ) ))If your data is confidential, please mask them first.
Best Regards,
Dale
- shado268 years agoHelper III
Hi Dale
I got where this error came from
I found some received date is after approved date
Like the below this are approved on 10 AM and alert are received on 12 PM
can we have IF to overright this
- v-jiascu-msft8 years agoMicrosoft Employee
Hi shado26,
How to override it? The formula in my last post will show up "Error" in the column.
ifmet = VAR sla2 = DATEDIFF ( DUMP_DATA_FROM_PURCHASE[start], DUMP_DATA_FROM_PURCHASE[end], SECOND ) RETURN IF ( WEEKDAY ( DUMP_DATA_FROM_PURCHASE[start],2 ) IN { 5, 6 }, "Week End approval", IF ( TIMEVALUE ( DUMP_DATA_FROM_PURCHASE[start] ) < TIME ( 9, 0, 0 ) || TIMEVALUE ( DUMP_DATA_FROM_PURCHASE[end] ) > TIME ( 18, 0, 0 ), "done", IF ( sla2 < 0,"Error",if(sla2 <= 5400, "Met", "Failed" ) ) ))Best Regards,
Dale
- shado268 years agoHelper III
i tried your forumla but its show all errorand its always mention the below
In DATEDIFF function, the start date cannot be greater than the end date
sorry to bothering you
on this can you make test and send to me - v-jiascu-msft8 years agoMicrosoft Employee
- shado268 years agoHelper III
- v-jiascu-msft8 years agoMicrosoft Employee
Hi shado26,
Please upgrade your Desktop to the latest version from https://www.microsoft.com/en-us/download/details.aspx?id=45331. Then you can use the formula freely. (No error about Datediff)
The question is how to define weekend when start and end aren't in a single day.
Best Regards,
Dale
- shado268 years agoHelper III
i want to thank you to help me on this its work fine now after instal the new version of Power PI
i have one question to ask
can we add on this to calculate the SLA from working hours
like Ex
if i received order on 5:30 PM
and approved next working day on 9:30
i calculation of SLA should be 30 min in evening and 30 min in morning to this will be met the SLA
another Ex
if i received order on 5:30 PM
but approved next working day on 10:30
this SLA for this will be 2 h for this should count as faild
many thanks
shadi
- v-jiascu-msft8 years agoMicrosoft Employee
Hi shado26,
I have a similar case today. You can add a new column to computer the work hours only. Please check the demo here.
AllInOne = VAR standardStart = IF ( TIMEVALUE ( [Start Time] ) < TIME ( 9, 0, 0 ), DATEVALUE ( [Start Time] ) + TIME ( 9, 0, 0 ), IF ( TIMEVALUE ( [Start Time] ) > TIME ( 17, 0, 0 ), DATEVALUE ( [Start Time] ) + TIME ( 17, 0, 0 ), [Start Time] ) ) VAR standardEnd = IF ( TIMEVALUE ( [End Time] ) < TIME ( 9, 0, 0 ), DATEVALUE ( [End Time] ) + TIME ( 9, 0, 0 ), IF ( TIMEVALUE ( [End Time] ) > TIME ( 17, 0, 0 ), DATEVALUE ( [End Time] ) + TIME ( 17, 0, 0 ), [End Time] ) ) VAR businessDay = CALCULATE ( SUMX ( DateTable, [IsWorkday] ), FILTER ( 'DateTable', 'DateTable'[Date] > [Start Time].[Date] && 'DateTable'[Date] < [End Time].[Date] ) ) RETURN IF ( [Start Time] > [End Time], 9999, IF ( [Start Time].[Date] = [End Time].[Date], DATEDIFF ( standardstart, standardend, HOUR ), [Business Days] * 8 + DATEDIFF ( TIMEVALUE ( standardstart ), TIME ( 17, 0, 0 ), HOUR ) + DATEDIFF ( TIME ( 9, 0, 0 ), TIMEVALUE ( standardend ), HOUR ) ) )Best Regards,
Dale
- shado268 years agoHelper III
thank for this tips
but what im lookiing for our noraml standard work time from 9 AM to 5 PM
we have 1 month during the year we start at 9 AM and End on 3 PM
how we can inculde this time in this month on main forumla
or can we create table for Workday and include working time ??
to make more easy lets us say on Jan our working time from 9 AM to 5 PM
and Feb will be from 9 AM to 3 PM