Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

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:

 

TestDate = VAR datedifferenceone = DATEDIFF(Changes[creationDate2], Changes[closureDate2],DAY)
return
IF(Changes[creationDate2] = [closureDate2],
(Changes[weekDayDiff] -1) + (TIMEVALUE(Changes[closureTime]-Changes[creationTime])),
((Changes[weekDayDiff] -2) + (TIME(17,00,00) - Time(HOUR(Changes[creationDate2]),MINUTE(Changes[creationDate2]), SECOND(Changes[creationDate2])) + (Time(HOUR(Changes[closureDate2]), MINUTE(Changes[closureDate2]), SECOND(Changes[closureDate2]))-TIME(08,00,00))*2.667)
)
)
 

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)

 

 
I've started the following code, but i'm clueless on how to solve it;
 
TestToime =
var CreationCheck = IF(Changes[creationDate2] > TIME(17,00,00) || Changes[creationDate2] < TIME(08,00,00),1 , 0)
var ClosureCheck = IF(Changes[closureDate2] > TIME(17,00,00) || Changes[closureDate2] < TIME(08,00,00),1 , 0)

Return
IF(Changes[creationDate2] = [closureDate2],
(Changes[weekDayDiff] -1) + (TIMEVALUE(Changes[closureTime]-Changes[creationTime])),
((Changes[weekDayDiff] -2) + (if( CreationCheck = 1 && ClosureCheck = 1,
((TIME(17,00,00) - TIMEVALUE(Changes[creationDate2])) + (TIMEVALUE(Changes[closureDate2])-TIME(08,00,00))) *2.667 //converting decimal 24 hours to decimal 9 hour workhours, "havent filled 3e statement with something usefull yet"
 
)
)
)
)

 

 

 

Sorry for the long question...

 

2 REPLIES 2
Anonymous
Not 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. 

Icey
Community Support
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

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.