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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gvlado
Helper II
Helper II

Calculate working time by shifts - sum hours by shifts by calendar day

Dear all 
I couldn't find a solution for calculating working time in the shifts.
For example how many hours in which shift bus and driver were working.

gvlado_0-1665749390848.png

I would be happy to get some knowledge / solution.
Here it is excel table

Bus and drivers table     
#BusDriverStart dateStart timeEnd dateEnd timeNote
1B01Jim2022-01-0304:002022-01-0400:00 
4B01Steve2022-01-0505:002022-01-0516:00 
2B02Mike2022-01-0207:002022-01-0218:00 
3B02Steve2022-01-0609:002022-01-0700:10 
5B03Mike2022-01-0705:002022-01-0902:00 
        
 Shift definition table     
 #ShiftStartEnd  Note
 1Shift 107:0015:00  Date start on hour 00:00
 2Shift 215:0023:00   
 3Shift 323:0007:00   
        
Desired table 1      
#BusDateShift 1Shift 2Shift 3TotalNote
1B012022-01-0308:0008:0004:0020:00Shift 3= 3 h in morning + 1 h at evening
2B012022-01-0408:0008:0008:0024:00Shift 3= 1 h at evening + 7 h in the mornng
3B012022-01-0508:0001:0002:0011:00Shift 3 = 2 h in the morning
4B022022-01-0208:0003:0000:0011:00Shift 3= 0 in the morning and 0 at evening
5B022022-01-0606:0008:0001:0015:00Shift 3= 1 h at evening
6B022022-01-0700:0000:0000:100:10Shift 3= 10 min in the morning
7B032022-01-0708:0008:0003:0019:00Shift 3= 2 h in morning + 1 h at evening
8B032022-01-0808:0008:0008:0024:00Shift 3= 1 h at evening + 7h in the mornng
9B032022-01-0900:0000:0002:002:00Shift 3 = 2 h in the morning
 Subtotal 54:0044:0028:10126:10 
Desired table 2      
#DriverDateShift 1Shift 2Shift 3TotalNote
1Jim2022-01-0308:0008:0004:0020:00Shift 3= 3 h in morning + 1 h at evening
2Jim2022-01-0408:0008:0008:0024:00Shift 3= 7 h in the morning +1 h at evening
3Steve2022-01-0508:0001:0002:0011:00Shift 3= 2 h in the morning
4Steve2022-01-0606:0008:0001:0015:00Shift 3= 1 h at evening
5Steve2022-01-0700:0000:0000:100:10Shift 3=10 min in the morning
6Mike2022-01-0208:0003:0000:0011:00No Shift 3
7Mike2022-01-0708:0008:0003:0019:00Shift 3= 2 h in morning + 1 h at evening
8Mike2022-01-0808:0008:0008:0024:00Full day
9Mike2022-01-0900:0000:0002:002:00Shift 3= 2 h in the morning
 Subtotal 54:0044:0028:10126:10 
6 REPLIES 6
vanessafvg
Super User
Super User

Its a little confusing your logic for the shift time tables.  What is the business rules here?  Can you explain more about the 3 shifts?

 

i would join the date and time and use a datediff in a calculated column to get each total hours.  

 

however the shift aspect is not easy to work out with the information given , what is the rule for the shifts.  There seeems to be overlapping information which doesn't make sense with what you have given.

 

i created a power bi file, maybe this can help.

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Thanks @vanessafvg for your effort
Little explanation for shifts
Calendar day is from 00:00 hours to 24:00 (23:59) hours
Working shifts are divided into 3 parts that are spread over two calendar days (3 times 8 hours)
Shift 1 starts in the morning (07:00) of the calendar day and lasts until 15:00
Shift 2 starts at 15:00 of the calendar day and lasts until 23:00
Shift 2 starts at 23:00 of the calendar day and lasts until 07:00 the next calendar day.
So DATEDIFF is not working, and that is the problem
It should be some kind of time difference that will cover two calendar days - for example from 23:00 today until 01:00 tomorrow should be 02:00 hours and zero minutes.

did you look at the file i created?  i combined date and time so that should resolve that issue.  please see the file i created and the measure hours and let me know what in it specifically is wrong.  





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Your pbx is ok but it doesnt give me answer by shifts.
See Desired tables
Should give information about how many hours bus did in first, second and third shift that calendar day.
(Bus 01, on date YYYY-MM-DD, on Shift X = hh:mm, and total hours for this calendar day)
I think the problem is how to divide one calendar day in 3 parts (shifts)
Thanks for your effort - it is not easy

yes but what is complicated to undersand is how one bus can have 2 shifts at the same time, in order to do this cleverly you need to provide those shift patterns.  you have the same bus at shift 1 and shift 2 at the same time, which doesn't make sense.  Can you explain? 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Simple -> see desired table
For example :
Due to I pay different amounts for different shifts I have to know how many working hours and minutes the driver was working in which shift.
But don't bother if it is too complicated! Hope I will find another way with "IF" (hh:mm<00:00 and >=23:00) then Shift3 .... to get a new pattern and then ... something 
I still don't have clear idea 
The point is to get from Bus and driver table -> the Desired table by the rule of the Shift table

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.