Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sovereignauto
Helper III
Helper 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#M...

 

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!!  

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community 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)



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community 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)



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community 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. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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)
 
 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.