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