Forum Discussion
sovereignauto
5 years agoHelper III
Working hours, Saturdays different
Good Afternoon, I have looked at a number of posts including this one: https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Duration-Working-Hours/m-p/481543#M182 but a) they...
- 5 years ago
sovereignauto Hard to say without knowing your data. I do have a much improved version of that calculation in my book, DAX Cookbook. It is recipe 10 in Chapter 2. You can grab the example PBIX files from github. gdeckler/DAXCookbook (github.com)
Greg_Deckler
5 years agoCommunity Champion
sovereignauto You would need to add equivalent variables for the Saturday stuff, do essentially the same calculations and then add the two calculation branches together. You could get the Saturday's doing this:
VAR __SaturdayNetWorkDays = COUNTX(FILTER(ADDCOLUMNS(CALENDAR(__dateStart,__dateEnd),"WeekDay",WEEKDAY([Date],2)),[WeekDay]=6),[Date])
Note the = 6 versus < 6.
sovereignauto
5 years agoHelper III
thanks Greg_Deckler , thought that would be the case.
any Idea why it woud calculate Zero for every row
mNetWorkDuration =
// Get the start and end dates
VAR __dateStart = MAX([DateReferred])
VAR __dateEnd = MAX(CLAIM[FirstClientContact])
// Calculate the Net Work Days between the start and end dates
VAR __NetWorkDays = COUNTX(FILTER(ADDCOLUMNS(CALENDAR(__dateStart,__dateEnd),"WeekDay",WEEKDAY([Date],2)),[WeekDay]<6),[Date])
// Set this to the start of the work day (7:30 AM)
VAR __startTime = TIME(7,30,0)
// Set this variable to the end of the work day (6:00 PM)
VAR __endTime = TIME(18,0,0)
// Calculate the duration of a full day, in this case in minutes
VAR __fullDayMinutes = DATEDIFF(__startTime,__endTime,MINUTE)
// Calculate teh number of full days, this accounts for the possibility that tickets start and end on the same day
VAR __fullDays = IF(__NetWorkDays < 2,0,__NetWorkDays-2)
// Calculate the total duration of all full days.
VAR __fullDaysDuration = __fullDays * __fullDayMinutes
// Calculate the start time of the current record
VAR __startDayTime = TIME(HOUR(__dateStart),MINUTE(__dateStart),SECOND(__dateStart))
// Caclulate the duration of time for the first day
VAR __startDayDuration = DATEDIFF(__startDayTime,__endTime,MINUTE)
// Calculate the end time of the current record
VAR __endDayTime = TIME(HOUR(__dateEnd),MINUTE(__dateEnd),SECOND(__dateEnd))
// Calculate the duration of time for the last day
VAR __endDayDuration = DATEDIFF(__startTime,__endDayTime,MINUTE)
// The total duration is the duration of all full days plus the durations of time for the first and last days
RETURN
IF(__NetWorkDays=1,DATEDIFF(__dateStart,__dateEnd,MINUTE),__fullDaysDuration + __startDayDuration + __endDayDuration)