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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
nony97
Regular Visitor

adjust query to exclude holidays and weekends

i wrote this query that calulate work hours (8:30 to 16:30) and  need it to exclude holidayes ( i have a seperate holiday table that has holiday start date and holiday end date) and i need it to exclude weekends (friday and saturday)

 here is the dax power query 

 

workhours without out of working hours =
VAR WorkTimeStart = TIME ( 08, 30, 00 )
VAR WorkTimeEnd = TIME ( 16, 30, 10 )
VAR WorkingHours = ( WorkTimeEnd - WorkTimeStart )

-- Start and End date/time on current row
VAR StartingDateTime = [Created  - Copy]
VAR EndingDateTime   = [Completed - Copy]

VAR StartingTime= StartingDateTime - TRUNC ( StartingDateTime )
VAR StartingDate = StartingDateTime - StartingTime

VAR EndingTime = EndingDateTime - TRUNC ( EndingDateTime )
VAR EndingDate = EndingDateTime - EndingTime

-- Adjust start/end times to fall within working hours.
VAR StartingTimeEffective =
    MIN (
        MAX ( StartingTime, WorkTimeStart ),
        WorkTimeEnd
    )
VAR EndingTimeEffective =
    MAX (
        MIN ( EndingTime, WorkTimeEnd ),
        WorkTimeStart
    )
-- Adjust for hours not worked on StartingDate
--   StartingTimeOffset will always be <= 0
VAR StartingTimeOffset =
    WorkTimeStart - StartingTimeEffective
-- Adjust for hours not worked on EndingDate
--   EndingTimeOffset will always be <= 0
VAR EndingTimeOffset =
    EndingTimeEffective - WorkTimeEnd
VAR DayCount =
    EndingDate - StartingDate + 1
VAR TotalTimeInDays =
    DayCount * WorkingHours + StartingTimeOffset + EndingTimeOffset
VAR TotalTimeInHours =
    TotalTimeInDays * 24
VAR TotalTimeInHoursRounded =
    ROUNDDOWN ( TotalTimeInHours, 0 )
RETURN
    TotalTimeInHoursRounded
1 REPLY 1
lbendlin
Super User
Super User

need it to exclude holidayes ( i have a seperate holiday table that has holiday start date and holiday end date) and i need it to exclude weekends (friday and saturday)

Have you considered using the standard NETWORKDAYS DAX function?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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