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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
javirmerino
Helper III
Helper III

Date Time + x Working Hours (DAX)

First of all; thanks to everyone that's helped me out this week. I really appreciate it, guys!

 

I'm trying to calculate an expected end time and date based on a start time and a priority status so i can determine if the request was completed within SLA. Weekends and holidays need to be excluded from this calculation, as well as hours outside of the operational 9-5. For example, an urgent incident received at 16:59 would be due at 12:59 the next working day (+4 working hours), while an urgent incident received any time after that but before 9am would be due by 13:00..

 

An added level of complexity would be that the expected hours to complete each incident varies depending on the priority level;

 

UrgencyHours
Low40
Medium24
High16
Very High8
Urgent4


Fortunately i have NextWorkingDay, IsWeekDay and IsHolidayUK as fields within my date dimension table, as well as a number of pre-calculated fields such as the correct StartingPoint.

 

IDReceivedReceivedDateReceivedTimeNextWorkingDayStartDateStartTimeStartingPointUrgency
7293706/01/2020 11:0706/01/202011:07:2907/01/202006/01/202011:07:3006/01/2020 11:07Urgent
7302107/01/2020 11:1307/01/202011:13:3508/01/202007/01/202011:13:3607/01/2020 11:13Urgent
7330310/01/2020 16:2410/01/202016:24:2313/01/202010/01/202016:24:2310/01/2020 16:24Normal
7330710/01/2020 16:5310/01/202016:53:4513/01/202010/01/202016:53:4610/01/2020 16:53Very High
7406528/01/2020 08:0828/01/202008:08:5129/01/202029/01/202009:00:0029/01/2020 09:00Low
7417929/01/2020 15:3129/01/202015:31:3530/01/202029/01/202015:31:3629/01/2020 15:31Normal
7419129/01/2020 16:4029/01/202016:40:5030/01/202029/01/202016:40:5029/01/2020 16:40Low
7428731/01/2020 13:0331/01/202013:03:4903/02/202031/01/202013:03:4931/01/2020 13:03Urgent
7441904/02/2020 16:3104/02/202016:31:5005/02/202004/02/202016:31:5004/02/2020 16:31High
7443605/02/2020 09:3905/02/202009:39:3006/02/202005/02/202009:39:3105/02/2020 09:39Normal

 

However, i have absolutely no idea where to start with the calculation so was wondering if anyone had written something similar, previously? I've found some similar answers from several years back but these were all relative to Power Query/M Language as opposed to DAX - so i'm wondering if its even possible?!

5 REPLIES 5
PatrickT
New Member

@javirmerino Did you find a solution? i am searching for this aswell.

v-juanli-msft
Community Support
Community Support

Hi @javirmerino 

Is this problem sloved? 
If it is sloved, could you kindly accept it as a solution to close this case?
If not, please feel free to let me know.
 
Best Regards
Maggie

hi @v-juanli-msft , i'm afraid its not quite resolved. The answer provided would be perfect if there was not a consideration for working hours and the time continued overnight.

 

However, i need to calculate a total duration based on office hours only. For example, If something Urgent is received at 16:59 on Friday they would have 4 working hours to complete. The DueDate should therefore be 12:59 on Monday not 20:59 on the same day.

 

i've managed to write the script in excel but am having trouble converting this into a measure due to the number of nested If formulae;

 

=IF([@[Required Completion Date]]=0,IF([@Urgency]="Urgent",
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))>=0.7083333,SUM(WORKDAY([@WorkingDayRecieved],1,bhols),0.541666667),
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"),urgent)>=0.7083333,WORKDAY([@WorkingDayRecieved],1,bhols)+0.375+SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"),urgent)-0.7083333,IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))<0.375,WORKDAY([@WorkingDayRecieved],0,bhols)+0.541666667,WORKDAY([@WorkingDayRecieved],0,bhols)+SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"),urgent)))),
IF([@Urgency]="Very High",
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))>=0.7083333,SUM(WORKDAY([@WorkingDayRecieved],1,bhols),0.7083333),
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"),veryhigh)>0.708333333333333,WORKDAY([@WorkingDayRecieved],1,bhols)+0.375+SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"),veryhigh)-0.7083333,[@WorkingDayRecieved]+veryhigh)),IF([@Urgency]="High",
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))>=0.7083333,SUM(WORKDAY([@WorkingDayRecieved],2,bhols),0.7083333),
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))<=0.375,WORKDAY([@WorkingDayRecieved],1,bhols)+0.70833333,WORKDAY([@WorkingDayRecieved],high,bhols)+SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day")))),
IF([@Urgency]="normal",
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))>=0.7083333,SUM(WORKDAY([@WorkingDayRecieved],3,bhols),0.7083333),
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))<0.375,WORKDAY([@WorkingDayRecieved],2,bhols)+0.70833333,WORKDAY([@WorkingDayRecieved],normal,bhols)+SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day")))),
IF([@Urgency]="low",
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))>=0.7083333,SUM(WORKDAY([@WorkingDayRecieved],5,bhols),0.7083333),
IF(SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day"))<0.375,WORKDAY([@WorkingDayRecieved],low,bhols)+0.70833333,WORKDAY([@WorkingDayRecieved],low,bhols)+SUM(CONVERT(HOUR([@WorkingDayRecieved]),"hr","day"),CONVERT(MINUTE([@WorkingDayRecieved]),"mn","day")))),""))))),[@[Required Completion Date]])

 

vanessafvg
Super User
Super User

@javirmerino   you could something like this, just need to adjust for your names

 

expected end time =
IF (
    isworkday = 1
        && isholiday = 0,
    issues[StartingPoint] + TIME ( RELATED ( lookup[Hours] )00 ),
    BLANK ()
)





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Thanks @vanessafvg, thats about as far as i got, too. This would be my solution if it were just adding hours, but i need it to add working hours only.

 

Somehow, the hours added timer needs to stop at 5pm and restart on 9am the next working day. The issue being that Low priority requests have a 40 hour SLA so they wouldnt even be due in the same week, let alone the same day!

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.