Forum Discussion
Working hours, Saturdays different
Good Afternoon,
I have looked at a number of posts including this one:
but a) they dont have saturday hours built in that are differnt to mon-friday and b) also the above just returns 0 for me when i add it as as a column.
1. Date_Recvied - This could be "out of hours" but will not be blank
2. Date_called - This could be blank
Woking hours are 9-5:30 - Mon-Fri 9-1 Saturday
Thank you!!
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)
3 Replies
- Greg_DecklerCommunity Champion
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_DecklerCommunity 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.
- sovereignautoHelper III
thanks Greg_Deckler , thought that would be the case.
any Idea why it woud calculate Zero for every rowmNetWorkDuration =// Get the start and end datesVAR __dateStart = MAX([DateReferred])VAR __dateEnd = MAX(CLAIM[FirstClientContact])// Calculate the Net Work Days between the start and end datesVAR __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 minutesVAR __fullDayMinutes = DATEDIFF(__startTime,__endTime,MINUTE)// Calculate teh number of full days, this accounts for the possibility that tickets start and end on the same dayVAR __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 recordVAR __startDayTime = TIME(HOUR(__dateStart),MINUTE(__dateStart),SECOND(__dateStart))// Caclulate the duration of time for the first dayVAR __startDayDuration = DATEDIFF(__startDayTime,__endTime,MINUTE)// Calculate the end time of the current recordVAR __endDayTime = TIME(HOUR(__dateEnd),MINUTE(__dateEnd),SECOND(__dateEnd))// Calculate the duration of time for the last dayVAR __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 daysRETURNIF(__NetWorkDays=1,DATEDIFF(__dateStart,__dateEnd,MINUTE),__fullDaysDuration + __startDayDuration + __endDayDuration)