Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
i wrote the following dax query that calculate work hourse 8am to 5 pm however i need it to exclude the weekend (exclude saturday and friyday) please help
for example this is how it currenlty is being calculatined
start date | end date | work hourse |
4/22/2022 3:00 | 4/23/2022 14:04:00 | 15 |
this is how i want it to be
start date | end date | work hourse |
4/22/2022 3:00 | 4/23/2022 14:04:00 | 0 |
and here is the query
workhours new =
-- Working Start and End time
VAR WorkTimeStart = TIME ( 08, 00, 00 )
VAR WorkTimeEnd = TIME ( 17, 10, 10 )
VAR WorkingHours = ( WorkTimeEnd - WorkTimeStart )
-- Start and End date/time on current row
VAR StartingDateTime = [start date]
VAR EndingDateTime = [end date]
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
RETURN
TotalTimeInHours
Solved! Go to Solution.
The standard approach is to decide on the desired level of granularity (does it need to be minutes, or are quarter hours or higher enough?), then you GENERATESERIES of these timeslots and finally you do an INTERSECT with your "permitted" date range excluding your definition of weekend and holidays.
This becomes interesting when your users work across timezones or have regional holiday differences.
The standard approach is to decide on the desired level of granularity (does it need to be minutes, or are quarter hours or higher enough?), then you GENERATESERIES of these timeslots and finally you do an INTERSECT with your "permitted" date range excluding your definition of weekend and holidays.
This becomes interesting when your users work across timezones or have regional holiday differences.
No that is not acceptable, because if the order came on Saturday it will start counting the hours which us wrong
Real life may not care what you consider to be "wrong". Better be prepared for such a scenario.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
17 | |
10 | |
8 | |
8 | |
7 |