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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Powerbiuser667
New Member

Calculating elapsed business hours

Who can help me with this formula?

I’m trying to calculate the business hours that have elapsed between the moment a record has been opened and the moment that record is closed. After receiving error after error I finally have a code that doesn’t give me an error, but is still not showing me the correct numbers. What should the code look like? I'm clearing doing something very wrong (not very experienced yet).

 

This is what I have

 

NetWorkHours =
VAR BusinessStartHour = TIME(8;00;00) // Set the start of business hours (8:00 AM)
VAR BusinessEndHour = TIME(18, 0, 0) // Set the end of business hours (6:00 PM)
VAR StartDate = [OpenedDateTime]
VAR EndDate = [ClosedDateTime]

VAR NetWorkDays = NETWORKDAYS(StartDate, EndDate)

VAR StartWorkHours = IF(TIME(HOUR(StartDate), MINUTE(StartDate), SECOND(StartDate)) < BusinessEndHour, BusinessEndHour - TIME(HOUR(StartDate), MINUTE(StartDate), SECOND(StartDate)), 0)
VAR EndWorkHours = IF(TIME(HOUR(EndDate), MINUTE(EndDate), SECOND(EndDate)) > BusinessStartHour, TIME(HOUR(EndDate), MINUTE(EndDate), SECOND(EndDate)) - BusinessStartHour, 0)

VAR NetWorkHours =
IF(
NetWorkDays > 0,
(NetWorkDays * (BusinessEndHour - BusinessStartHour)) + StartWorkHours + EndWorkHours,
IF(
StartDate >= EndDate || StartDate = EndDate,
0,
StartWorkHours + EndWorkHours
)
)

RETURN
NetWorkHours // Returns the net work hours without rounding

2 REPLIES 2
Anonymous
Not applicable

Hi @Powerbiuser667 ,

Have you solved your problem? If solved please mark the reply in this post which you think is helpful as a solution to help more others facing the same problem to find a solution quickly, thank you very much!
If the problem hasn't been solved yet, could you please provide the results you're getting with the DAX you're using and what you're hoping to get, that would be helpful!

Best Regards,
Dino Tao

123abc
Community Champion
Community Champion

Here is modified Dax Measure:

 

NetWorkHours =
VAR BusinessStartHour = TIME(8, 0, 0) // Set the start of business hours (8:00 AM)
VAR BusinessEndHour = TIME(18, 0, 0) // Set the end of business hours (6:00 PM)
VAR StartDate = [OpenedDateTime]
VAR EndDate = [ClosedDateTime]

VAR NetWorkDays = NETWORKDAYS(StartDate, EndDate)

VAR StartWorkHours =
IF(
TIME(HOUR(StartDate), MINUTE(StartDate), SECOND(StartDate)) < BusinessStartHour,
BusinessStartHour - TIME(HOUR(StartDate), MINUTE(StartDate), SECOND(StartDate)),
0
)

VAR EndWorkHours =
IF(
TIME(HOUR(EndDate), MINUTE(EndDate), SECOND(EndDate)) > BusinessEndHour,
TIME(HOUR(EndDate), MINUTE(EndDate), SECOND(EndDate)) - BusinessEndHour,
0
)

VAR NetWorkHours =
IF(
NetWorkDays > 0,
(NetWorkDays - 1) * (BusinessEndHour - BusinessStartHour) + StartWorkHours + EndWorkHours,
IF(
StartDate < EndDate && StartDate <> EndDate,
StartWorkHours + EndWorkHours,
0
)
)

RETURN
NetWorkHours // Returns the net work hours without rounding

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.