Forum Discussion
Calculating processing time in workdays + time in decimals
I've been struggling with calculating processing time in workdays and processing time in workhours.
i've used the following function to calculate the DateDiff in workdays between 2 dates:
= (InitialDate as date, FinalDate as date ) as number =>
let
DaysBetweenDates = Duration.Days(FinalDate-InitialDate),
DaysList = List.Dates(List.Min({InitialDate,FinalDate}),Number.Abs(DaysBetweenDates)+1, Duration.From(1)),
WeekDaysList = List.Select(DaysList, each (Date.DayOfWeek(_, Day.Monday) < 5) ),
WorkingDays = (if DaysBetweenDates < 0 then -1 else 1) * List.Count(WeekDaysList)
in
WorkingDays
now this works fine, but it'll give a processing time of 1 day, for a ticket that has been created AND closed on the same day. In those cases it's simple; closureTime - creationTime. for tickets that span multiple days this doens't work tho. Since our company's opening times are from 08:00:00 to 17:00:00, i tried to calculate the difference between the creationTime and 17:00:00 (on the creationday), and add that to the difference of 08:00:00 and the closureTime (on the closingDay) and add that SUM to the whole workdays that it had already calculated. This works fine, but i noticed some tickets were being created/closed outside of workinghours, so subtracting them gives negative values. How do i remedy this? This is what i have so far regarding the timediff:
values:
creationDate2: 13-4-2022 21:01:25
closureDate2: 14-4-2022 08:52:00
weekDayDiff function gives: 2 days
TestDate (the code above): -0,07 workingdays (which is not correct)
Sorry for the long question...
2 Replies
- Icey
Community Support
Hi Anonymous ,
There are both "creationDate2" and "creationTime", and you both use TIMEVALUE for them. What's the difference between them?
Could you share more details about your data structure?
Reference:
How to Get Your Question Answered Quickly - Microsoft Power BI Community
How to provide sample data in the Power BI Forum - Microsoft Power BI Community
Best Regards,
Icey
- AnonymousNot applicable
Hi Icey,
creationTime is a derivative of creationDate2, they have the same function in this case. I did do some other calculations where i couldn't get it to work with just creationDate2, and since i'm an utter noob in powerBI, deriving the timevalue from creationDate2 to work with it separately looked like a good idea :0.