Quantcast
Channel: Power Query topics
Viewing all articles
Browse latest Browse all 31096

Dax that calculate employee hours

$
0
0

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 dateend datework hourse
4/22/2022 3:004/23/2022 14:04:0015

 this is how i want it to be 

start dateend datework hourse
4/22/2022 3:004/23/2022 14:04:000

 

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

 


Viewing all articles
Browse latest Browse all 31096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>