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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
jbrines
Advocate III
Advocate III

Help working out actual time which includes working hours

Hi Guys,

 

I got help on here to create this code, the issue is that it doesn't take working hours in to consideration, can the code be ammended to take these hours in to consideration.

 

Working hours

Mon - 8am - 5pm

Tue - 8am - 5pm

Wed 8am - 5pm

Thurs 8am - 5pm

Fri 8am - 3:30pm

 

Code

 

Actual Time = 
VAR StartDT = SELECTEDVALUE ( 'Results Data'[Created Date] )
VAR EndDT   = SELECTEDVALUE ( 'Results Data'[Closed Date] )

RETURN
IF (
    ISBLANK ( EndDT ) || EndDT < StartDT,
    BLANK(),
    
    VAR StartDate = INT ( StartDT )
    VAR EndDate   = INT ( EndDT )

    VAR SameDay = StartDate = EndDate

    -- Check working day
    VAR IsStartWorkingDay =
        WEEKDAY ( StartDate, 2 ) <= 5 &&
        NOT ( StartDate IN UKBankHols )

    VAR IsEndWorkingDay =
        WEEKDAY ( EndDate, 2 ) <= 5 &&
        NOT ( EndDate IN UKBankHols )

    -- Full working days between start and end
    VAR FullWorkingDays =
        MAX (
            0,
            NETWORKDAYS ( StartDate, EndDate, 1, UKBankHols )
                - IF ( IsStartWorkingDay, 1, 0 )
                - IF ( IsEndWorkingDay, 1, 0 )
        )

    -- Partial day contributions (calendar hours)
    VAR StartDayFraction =
        IF (
            IsStartWorkingDay,
            1 - ( StartDT - StartDate ),
            0
        )

    VAR EndDayFraction =
        IF (
            IsEndWorkingDay,
            EndDT - EndDate,
            0
        )

    VAR TotalCalendarDays =
        IF (
            SameDay,
            IF ( IsStartWorkingDay, EndDT - StartDT, 0 ),
            FullWorkingDays + StartDayFraction + EndDayFraction
        )

    RETURN
        MAX ( 0, TotalCalendarDays )
)
1 ACCEPTED SOLUTION
jbrines
Advocate III
Advocate III

Guys, 

 

On reflection the formula is fine, so I don't now need help thanks and thanks to @ryan_mayu and @FBergamaschi for replying.

View solution in original post

5 REPLIES 5
v-pnaroju-msft
Community Support
Community Support

Hi @jbrines,

We are glad to hear that your issue has been resolved. Kindly share the solution that resolved it, as this may benefit other members of the community. If you have any further queries, please feel free to contact the Microsoft Fabric community.

Thank you.

 

v-pnaroju-msft
Community Support
Community Support

Hi jbrines,

Thank you for confirming that the formula is working as expected. We appreciate you taking the time to follow up, and we are grateful to @FBergamaschi and @ryan_mayu for their inputs. If you have any further queries, please feel free to contact the Microsoft Fabric community.

Thank you.

jbrines
Advocate III
Advocate III

Guys, 

 

On reflection the formula is fine, so I don't now need help thanks and thanks to @ryan_mayu and @FBergamaschi for replying.

ryan_mayu
Super User
Super User

@jbrines 

could you pls provide some sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




FBergamaschi
Super User
Super User

Hi @jbrines 

your code is a measure, of course.

 

Can you illustrate what the measure purpose is, what is actual outcome is, and what data model it is used in?

 

This will make it easier to answer you

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.