Active Member
January 12, 2020
Hi, I have a question regarding calculation of hours worked. The employees use a GPS check in system that time stamps the start and end of each job. They can, and do, concurrent services (this is a dog walking / pet sitting business). Currently I am using a pivot table to assemble the data, and doing a MIN and MAX function to pull the beginning and end times for each employee, every day.
The problem with using the MIN and MAX function, is that there are gaps in time that are not accounted for. I currently have to search for and manually subtract gap time from each day. Time consuming and the potential for errors is real. Is there a formula that would be able to look through a series of check in and check out times and total the actual number of working hours in a day? I will give an example of hours below.
Employee | Date_Check_in1 | System_Check_in | System_Check_out | Service |
CL | 12/29/2019 | 3:34:08 PM | 4:13:06 PM | 5 |
CL | 12/29/2019 | 12:24:28 PM | 1:04:26 PM | 5 |
CL | 12/29/2019 | 10:04:39 AM | 12:12:36 PM | 1 |
CL | 12/29/2019 | 9:49:33 AM | 11:44:31 AM | 2 |
CL | 12/29/2019 | 9:44:29 AM | 11:39:12 AM | 1 |
CL | 12/29/2019 | 9:03:31 AM | 9:35:36 AM | 5 |
The MIN /MAX pulls the hours worked as 07:09 (9:03:31 - 4:13:06), but the actual time worked is 04:18
Thanks in advance for any suggestion!
Trusted Members
December 20, 2019
Active Member
January 12, 2020
Purfleet, they are separate clients and separate jobs but they are done together (the dogs are all walked and exercised at the same time) the pickup and dropoff times are going to be different. The employees get piece rate compensation and are payed per job worked, they must stay separate.
Trusted Members
December 20, 2019
I am sure that i have seen a video where someone came up with a mad array forumla that could isolate the overlapping times and work it back (probably Mike Girvin) but i cant find it anywhere.
There must be an easier way than what i have just done as it is really complicated! But I have also tested for multiple overlapping periods and it does appear to be working.
Data MUST be sorted by column C Smallest to largest and the end time is in C8, but we might be able to work around that at some point, but my head hurts now! Also the VBA is not dynamic - ie it will only work for 6 rows of data and the header at the moment, otherwise formulas will need dragging down and c8 will need ot move.
Purfleet
PS happy to see any other suggestions, as i think i have confused myself here and over done it.
VIP
Trusted Members
June 25, 2016
Active Member
January 12, 2020
Purfleet, thank you for breaking this down but testing this has been really problematic. I did LOL at the file name you gave your solution, this has been a nightmare for me as well. The VBA would need to be more nimble than this and I cannot get it to work when filtering for different data.
SunnyKow this tests very well, with a catch. Real world data set for me will not always have the System_Check_out times be in the same ascending order as the System_Check_in times, so the IF/AND formula being dependent on the cell below to be a greater number throws it off.
Trusted Members
December 20, 2019
Firstly i would like to say that Sunny's method is nicer if you can get it to work, however a macro can be useful if it has to do a lot of repetitive tasks or be done multiple times - its just a simple trade off - is it worth 2 or 3 hours of coding etc to save 10 seconds once a month? Probably not, but if it was to save 30 seconds 100 times a month, then yes.
In the macro i forgot that the formula in Column G had to be an array, so it wasn't calculating correctly - that has now been fixed.
The VBA would need to be more nimble than this and I cannot get it to work when filtering for different data.
When i start with a problem like this i usually get something like the attached as a Proof of Concept, especially when i don't know the data or not 100% sure what the output should look like.
Ranges can be extended and made dynamic without too many issues
So you need to filter before calculating? I assume that there will be multiple employees in the dataset that will need filtering and then calculating? If that is the case, then again it would be quite easy to loop through all employees, filter, copy to a new sheet and then, the hard bit which we have already done, calculate the time worked.
Maybe you can upload a larger dataset so we can test?
Purfleet
VIP
Trusted Members
June 25, 2016
Thanks Purfleet
Hi Michael
Without a large range of real-world sample data and the expected result, it is extremely difficult to find a solution (if any).
Creating a solution from scratch (using only formulas and no VBA) is a hit and miss. Sometimes you are lucky and sometimes not.
Googling didn't help one bit.
Attached is my final try.
Good luck.
Sunny
1 Guest(s)