Calculating Shift Differential

TraceyLR

New Member
Joined
Jun 25, 2022
Messages
15
Office Version
  1. 2010
Platform
  1. Windows
I am trying to calculate the number of shift differential hours in cells R9-V15 for each day (as a daily total) and by the shift type based on the chart. The hours worked each day are Time In (Y) through Lunch Start (Z) PLUS Lunch End (AA) through Time Out (AB). Ignore the information in cells AD-AF
Can anybody please help me with my formula?
 

Attachments

  • 71722.JPG
    71722.JPG
    118 KB · Views: 26

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Are you missing a "Shift 1" block for weekdays? Also, how is the 1 hour from 11:00 PM Friday night leading to midnight, the beginning of Saturday, handled? Does that go on the previous week's tabulation? Are you open to either restructuring your weekend/weekday shift helper blocks or using those blocks to create a new set of helper cells that are more easily referenced by a formula?
 
Upvote 0
Are you missing a "Shift 1" block for weekdays? Also, how is the 1 hour from 11:00 PM Friday night leading to midnight, the beginning of Saturday, handled? Does that go on the previous week's tabulation? Are you open to either restructuring your weekend/weekday shift helper blocks or using those blocks to create a new set of helper cells that are more easily referenced by
Are you missing a "Shift 1" block for weekdays? Also, how is the 1 hour from 11:00 PM Friday night leading to midnight, the beginning of Saturday, handled? Does that go on the previous week's tabulation? Are you open to either restructuring your weekend/weekday shift helper blocks or using those blocks to create a new set of helper cells that are more easily referenced by a formula?
Hi thanks for replying. I did not enter a Shift 1 block for weekdays because shift differential is not earned during the weekday shift 1. Friday at 11pm is the start of Weekend Shift 3. Hours Worked Friday 11p-Sat 7a is Weekend shift 3. I am open to restructuring the table if it would make it works and makes it easier
 
Upvote 0
Are you missing a "Shift 1" block for weekdays? Also, how is the 1 hour from 11:00 PM Friday night leading to midnight, the beginning of Saturday, handled? Does that go on the previous week's tabulation? Are you open to either restructuring your weekend/weekday shift helper blocks or using those blocks to create a new set of helper cells that are more easily referenced by a formula?
If a shift begins Friday and ends Saturday its considered one continuous shift and recorded on Friday
 
Upvote 0
Are you missing a "Shift 1" block for weekdays? Also, how is the 1 hour from 11:00 PM Friday night leading to midnight, the beginning of Saturday, handled? Does that go on the previous week's tabulation? Are you open to either restructuring your weekend/weekday shift helper blocks or using those blocks to create a new set of helper cells that are more easily referenced by a formula?
If I change the table and in/out time format to numbers seems here's what it looks like
 

Attachments

  • dates in numbers.JPG
    dates in numbers.JPG
    99.2 KB · Views: 11
Upvote 0
Here is an approach to consider. To write a formula-based solution, it is much more convenient to structure the supporting information as shown below. The time card data can be left as is, but a formula is used to transpose it so that Sat-Fri become column headings and the times in/out become row headings (see the transposed block in AR3:AY6). The shift descriptions originally occupied the range X18:AG23. For the sake of completeness, I added the weekday Shift1 descriptions (even though those have no differential...I'll explain why below). This extends the entire shift description range from X18:AI23. I don't think you need this, but it is arguably easier to read (for us), but not so convenient for referencing with formulas. I'm assuming these shift definitions are fairly rigid from week to week (e.g. weekend Shift 1 is always 7 AM to 3 PM). If that is true, then it is convenient to generate the shift table with a formula using only the starting point for the week (the Saturday date for the week is input in the blue cell AM11). Excel treats dates as numbers (as you've shown in your most recent post) and midnight of every day has an integer value (no decimal component). So the orange helper cells in AP13:AQ36 represent the number of fractional days to add to the starting point (i.e., midnight the date in AM11) to generate the start and end dates/times for each shift. I calculated these numbers by simply subtracting the shift start and end dates from the reference "0" point for the week (again, midnight the date in AM11) and saving the results as values only. So these orange cells are static and added to any new week start date in AM11 to generate the new shift table...that's what the pink cells in AN13:AO36 do, and the plain text description of the shift is given in the yellow cells in AM13:AM36.

Then the main computation block is found in AS13:AY36. A single formula is used here (pulled throughout the table) to look above at the in/out times for each day and compute the amount of time (in hours) that falls within the shift described on each row to the left. To do this, the basic formula for a single work "session" consists of four parts to establish how the start and end times of the work session compare to the start and end times of the shift. And since each day consists of two work sessions (before lunch and after lunch), the formula in each cell is repeated for the other work session. These are added together to obtain the total time worked on that day (for that column) during that shift (for that row). Then above the computation table, the total hours worked each day is shown (gray cells in AS10:AY10), which can be compared to the total hours worked, as computed directly from the time card data (the gray cells in AS7:AY7). This is why I felt it was important to include the weekday Shift1 (non differential) times...it allows for an error check to confirm that all of the worked time indicated by the timecard data has been apportioned among the various shifts. Then another sum is taken of only the hours worked during shifts that receive the differential (the red cells in AS9:AY9).

Finally, a SUMPRODUCT formula is used to sum the hours that match the day and shift shown in the summary table (green cells in R9:V15). One note...I've noticed before that adding and subtracting times can lead to some numeric precision issues (due to limitations with how Excel (and other programs) store numbers). To avoid having 8 hours appear as 7.999998611107 in the summary table, I've wrapped the SUMPRODUCT formula with a ROUND formula to round the results to 4 decimal places (which creates a rounding error less than 0.5 seconds).

You should be able to reconstruct this approach using the clipboard icon in the upper left of the mini sheet to copy it to your clipboard and then navigate to an empty worksheet and paste into the same cell shown in the upper left of the posted mini sheet. Because of the size, I'm posting the sheet in two sections. To reconstitute the sheet, be sure to follow the italicized guidance in the last sentence.

I would consider deleting columns AK:AL as well as the shift definitions in X18:AI23 (they are not used anywhere and they are static...not changing when the week rolls over).
Book3
XYZAAABACADAEAFAGAHAI
7Time InLunch StartLunch EndTime Out
8
9SAT7/16/2022 4:007/16/2022 12:007/16/2022 12:457/17/2022 4:00
10SUN7/17/2022 2:007/17/2022 9:007/17/2022 9:457/18/2022 2:00
11MON7/18/2022 16:007/19/2022 10:007/19/2022 10:457/19/2022 16:00
12TUE7/19/2022 18:007/20/2022 15:007/20/2022 15:457/20/2022 18:00
13WED7/20/2022 6:007/20/2022 14:307/20/2022 15:157/21/2022 6:00
14THU7/21/2022 17:007/21/2022 21:007/21/2022 21:457/22/2022 17:00
15FRI7/22/2022 17:007/23/2022 0:007/23/2022 0:457/23/2022 17:00
16
17
18WEnd Sh3WEnd Sh1WEnd Sh2Shift3Shift2Shift1 (no differential)
19#######7/16/2022 7:007/16/2022 7:007/16/2022 15:007/16/2022 15:00##########################################
20#######7/17/2022 7:007/17/2022 7:007/17/2022 15:007/17/2022 15:00##########################################
21#######7/23/2022 7:007/23/2022 7:007/23/2022 15:007/23/2022 15:00##########################################
22####################################
23####################################
Sheet3


Book3
AKALAMANAOAPAQARASATAUAVAWAXAY
2SATSUNMONTUEWEDTHUFRI
3Time In44758.1744759.0844760.6744761.7544762.2544763.7144764.71
4Lunch Start44758.544759.3844761.4244762.6344762.644763.8844765
5Lunch End44758.5344759.4144761.4544762.6644762.6444763.9144765.03
6Time Out44759.1744760.0844761.6744762.7544763.2544764.7144765.71
7Total worked (h)23.2523.2523.2523.2523.2523.2523.25
8
9Total differential worked (h)23.2523.251615.2515.7515.2523.25
10Total worked (h)23.2523.2523.2523.2523.2523.2523.25
117/16/2022<- Week Beginning Sat
12StartEndShiftStartEndStartEnd
137/16/2022 0:007/16/2022 7:00WEnd Sh37/16/2022 0:007/16/2022 7:0000.2916673000000
147/16/2022 23:007/17/2022 7:00WEnd Sh37/16/2022 23:007/17/2022 7:000.9583331.29166754.99999900000
157/22/2022 23:007/23/2022 7:00WEnd Sh37/22/2022 23:007/23/2022 7:006.9583337.2916670000007.25
167/16/2022 7:007/16/2022 15:00WEnd Sh17/16/2022 7:007/16/2022 15:000.2916670.6257.25000000
177/17/2022 7:007/17/2022 15:00WEnd Sh17/17/2022 7:007/17/2022 15:001.2916671.62507.25000100000
187/23/2022 7:007/23/2022 15:00WEnd Sh17/23/2022 7:007/23/2022 15:007.2916677.6250000008
197/16/2022 15:007/16/2022 23:00WEnd Sh27/16/2022 15:007/16/2022 23:000.6250.9583338000000
207/17/2022 15:007/17/2022 23:00WEnd Sh27/17/2022 15:007/17/2022 23:001.6251.9583330800000
217/23/2022 15:007/23/2022 23:00WEnd Sh27/23/2022 15:007/23/2022 23:007.6257.9583330000002
227/17/2022 23:007/18/2022 7:00Shift37/17/2022 23:007/18/2022 7:001.9583332.2916670300000
237/18/2022 23:007/19/2022 7:00Shift37/18/2022 23:007/19/2022 7:002.9583333.291667007.9999990000
247/19/2022 23:007/20/2022 7:00Shift37/19/2022 23:007/20/2022 7:003.9583334.2916670007.9999990.99999900
257/20/2022 23:007/21/2022 7:00Shift37/20/2022 23:007/21/2022 7:004.9583335.2916670000700
267/21/2022 23:007/22/2022 7:00Shift37/21/2022 23:007/22/2022 7:005.9583336.291667000007.9999990
277/18/2022 15:007/18/2022 23:00Shift27/18/2022 15:007/18/2022 23:002.6252.9583330070000
287/19/2022 15:007/19/2022 23:00Shift27/19/2022 15:007/19/2022 23:003.6253.9583330015000
297/20/2022 15:007/20/2022 23:00Shift27/20/2022 15:007/20/2022 23:004.6254.9583330002.257.7500
307/21/2022 15:007/21/2022 23:00Shift27/21/2022 15:007/21/2022 23:005.6255.958333000005.250
317/22/2022 15:007/22/2022 23:00Shift27/22/2022 15:007/22/2022 23:006.6256.9583330000026
327/18/2022 7:007/18/2022 15:00Shift1 (no differential)7/18/2022 7:007/18/2022 15:002.2916672.6250000000
337/19/2022 7:007/19/2022 15:00Shift1 (no differential)7/19/2022 7:007/19/2022 15:003.2916673.625007.2500010000
347/20/2022 7:007/20/2022 15:00Shift1 (no differential)7/20/2022 7:007/20/2022 15:004.2916674.6250008.0000017.50000100
357/21/2022 7:007/21/2022 15:00Shift1 (no differential)7/21/2022 7:007/21/2022 15:005.2916675.6250000000
367/22/2022 7:007/22/2022 15:00Shift1 (no differential)7/22/2022 7:007/22/2022 15:006.2916676.625000008.0000010
Sheet3
Cell Formulas
RangeFormula
AS2:AY6AS2=TRANSPOSE(X9:AB15)
AS7:AY7AS7=((AS6-AS3)-(AS5-AS4))*24
AS9:AY9AS9=SUM(AS13:AS31)
AS10:AY10AS10=SUM(AS13:AS36)
AN13:AO36AN13=$AM$11+AP13
AS13:AY36AS13=((IF(AS$4>$AN13,AS$4-$AN13,0)-IF(AS$3>$AN13,AS$3-$AN13,0))-(IF(AS$4>$AO13,AS$4-$AO13,0)-IF(AS$3>$AO13,AS$3-$AO13,0)))*24 + ((IF(AS$6>$AN13,AS$6-$AN13,0)-IF(AS$5>$AN13,AS$5-$AN13,0))-(IF(AS$6>$AO13,AS$6-$AO13,0)-IF(AS$5>$AO13,AS$5-$AO13,0)))*24
Dynamic array formulas.
 
Upvote 0
Solution
Here is an approach to consider. To write a formula-based solution, it is much more convenient to structure the supporting information as shown below. The time card data can be left as is, but a formula is used to transpose it so that Sat-Fri become column headings and the times in/out become row headings (see the transposed block in AR3:AY6). The shift descriptions originally occupied the range X18:AG23. For the sake of completeness, I added the weekday Shift1 descriptions (even though those have no differential...I'll explain why below). This extends the entire shift description range from X18:AI23. I don't think you need this, but it is arguably easier to read (for us), but not so convenient for referencing with formulas. I'm assuming these shift definitions are fairly rigid from week to week (e.g. weekend Shift 1 is always 7 AM to 3 PM). If that is true, then it is convenient to generate the shift table with a formula using only the starting point for the week (the Saturday date for the week is input in the blue cell AM11). Excel treats dates as numbers (as you've shown in your most recent post) and midnight of every day has an integer value (no decimal component). So the orange helper cells in AP13:AQ36 represent the number of fractional days to add to the starting point (i.e., midnight the date in AM11) to generate the start and end dates/times for each shift. I calculated these numbers by simply subtracting the shift start and end dates from the reference "0" point for the week (again, midnight the date in AM11) and saving the results as values only. So these orange cells are static and added to any new week start date in AM11 to generate the new shift table...that's what the pink cells in AN13:AO36 do, and the plain text description of the shift is given in the yellow cells in AM13:AM36.

Then the main computation block is found in AS13:AY36. A single formula is used here (pulled throughout the table) to look above at the in/out times for each day and compute the amount of time (in hours) that falls within the shift described on each row to the left. To do this, the basic formula for a single work "session" consists of four parts to establish how the start and end times of the work session compare to the start and end times of the shift. And since each day consists of two work sessions (before lunch and after lunch), the formula in each cell is repeated for the other work session. These are added together to obtain the total time worked on that day (for that column) during that shift (for that row). Then above the computation table, the total hours worked each day is shown (gray cells in AS10:AY10), which can be compared to the total hours worked, as computed directly from the time card data (the gray cells in AS7:AY7). This is why I felt it was important to include the weekday Shift1 (non differential) times...it allows for an error check to confirm that all of the worked time indicated by the timecard data has been apportioned among the various shifts. Then another sum is taken of only the hours worked during shifts that receive the differential (the red cells in AS9:AY9).

Finally, a SUMPRODUCT formula is used to sum the hours that match the day and shift shown in the summary table (green cells in R9:V15). One note...I've noticed before that adding and subtracting times can lead to some numeric precision issues (due to limitations with how Excel (and other programs) store numbers). To avoid having 8 hours appear as 7.999998611107 in the summary table, I've wrapped the SUMPRODUCT formula with a ROUND formula to round the results to 4 decimal places (which creates a rounding error less than 0.5 seconds).

You should be able to reconstruct this approach using the clipboard icon in the upper left of the mini sheet to copy it to your clipboard and then navigate to an empty worksheet and paste into the same cell shown in the upper left of the posted mini sheet. Because of the size, I'm posting the sheet in two sections. To reconstitute the sheet, be sure to follow the italicized guidance in the last sentence.

I would consider deleting columns AK:AL as well as the shift definitions in X18:AI23 (they are not used anywhere and they are static...not changing when the week rolls over).
Book3
XYZAAABACADAEAFAGAHAI
7Time InLunch StartLunch EndTime Out
8
9SAT7/16/2022 4:007/16/2022 12:007/16/2022 12:457/17/2022 4:00
10SUN7/17/2022 2:007/17/2022 9:007/17/2022 9:457/18/2022 2:00
11MON7/18/2022 16:007/19/2022 10:007/19/2022 10:457/19/2022 16:00
12TUE7/19/2022 18:007/20/2022 15:007/20/2022 15:457/20/2022 18:00
13WED7/20/2022 6:007/20/2022 14:307/20/2022 15:157/21/2022 6:00
14THU7/21/2022 17:007/21/2022 21:007/21/2022 21:457/22/2022 17:00
15FRI7/22/2022 17:007/23/2022 0:007/23/2022 0:457/23/2022 17:00
16
17
18WEnd Sh3WEnd Sh1WEnd Sh2Shift3Shift2Shift1 (no differential)
19#######7/16/2022 7:007/16/2022 7:007/16/2022 15:007/16/2022 15:00##########################################
20#######7/17/2022 7:007/17/2022 7:007/17/2022 15:007/17/2022 15:00##########################################
21#######7/23/2022 7:007/23/2022 7:007/23/2022 15:007/23/2022 15:00##########################################
22####################################
23####################################
Sheet3


Book3
AKALAMANAOAPAQARASATAUAVAWAXAY
2SATSUNMONTUEWEDTHUFRI
3Time In44758.1744759.0844760.6744761.7544762.2544763.7144764.71
4Lunch Start44758.544759.3844761.4244762.6344762.644763.8844765
5Lunch End44758.5344759.4144761.4544762.6644762.6444763.9144765.03
6Time Out44759.1744760.0844761.6744762.7544763.2544764.7144765.71
7Total worked (h)23.2523.2523.2523.2523.2523.2523.25
8
9Total differential worked (h)23.2523.251615.2515.7515.2523.25
10Total worked (h)23.2523.2523.2523.2523.2523.2523.25
117/16/2022<- Week Beginning Sat
12StartEndShiftStartEndStartEnd
137/16/2022 0:007/16/2022 7:00WEnd Sh37/16/2022 0:007/16/2022 7:0000.2916673000000
147/16/2022 23:007/17/2022 7:00WEnd Sh37/16/2022 23:007/17/2022 7:000.9583331.29166754.99999900000
157/22/2022 23:007/23/2022 7:00WEnd Sh37/22/2022 23:007/23/2022 7:006.9583337.2916670000007.25
167/16/2022 7:007/16/2022 15:00WEnd Sh17/16/2022 7:007/16/2022 15:000.2916670.6257.25000000
177/17/2022 7:007/17/2022 15:00WEnd Sh17/17/2022 7:007/17/2022 15:001.2916671.62507.25000100000
187/23/2022 7:007/23/2022 15:00WEnd Sh17/23/2022 7:007/23/2022 15:007.2916677.6250000008
197/16/2022 15:007/16/2022 23:00WEnd Sh27/16/2022 15:007/16/2022 23:000.6250.9583338000000
207/17/2022 15:007/17/2022 23:00WEnd Sh27/17/2022 15:007/17/2022 23:001.6251.9583330800000
217/23/2022 15:007/23/2022 23:00WEnd Sh27/23/2022 15:007/23/2022 23:007.6257.9583330000002
227/17/2022 23:007/18/2022 7:00Shift37/17/2022 23:007/18/2022 7:001.9583332.2916670300000
237/18/2022 23:007/19/2022 7:00Shift37/18/2022 23:007/19/2022 7:002.9583333.291667007.9999990000
247/19/2022 23:007/20/2022 7:00Shift37/19/2022 23:007/20/2022 7:003.9583334.2916670007.9999990.99999900
257/20/2022 23:007/21/2022 7:00Shift37/20/2022 23:007/21/2022 7:004.9583335.2916670000700
267/21/2022 23:007/22/2022 7:00Shift37/21/2022 23:007/22/2022 7:005.9583336.291667000007.9999990
277/18/2022 15:007/18/2022 23:00Shift27/18/2022 15:007/18/2022 23:002.6252.9583330070000
287/19/2022 15:007/19/2022 23:00Shift27/19/2022 15:007/19/2022 23:003.6253.9583330015000
297/20/2022 15:007/20/2022 23:00Shift27/20/2022 15:007/20/2022 23:004.6254.9583330002.257.7500
307/21/2022 15:007/21/2022 23:00Shift27/21/2022 15:007/21/2022 23:005.6255.958333000005.250
317/22/2022 15:007/22/2022 23:00Shift27/22/2022 15:007/22/2022 23:006.6256.9583330000026
327/18/2022 7:007/18/2022 15:00Shift1 (no differential)7/18/2022 7:007/18/2022 15:002.2916672.6250000000
337/19/2022 7:007/19/2022 15:00Shift1 (no differential)7/19/2022 7:007/19/2022 15:003.2916673.625007.2500010000
347/20/2022 7:007/20/2022 15:00Shift1 (no differential)7/20/2022 7:007/20/2022 15:004.2916674.6250008.0000017.50000100
357/21/2022 7:007/21/2022 15:00Shift1 (no differential)7/21/2022 7:007/21/2022 15:005.2916675.6250000000
367/22/2022 7:007/22/2022 15:00Shift1 (no differential)7/22/2022 7:007/22/2022 15:006.2916676.625000008.0000010
Sheet3
Cell Formulas
RangeFormula
AS2:AY6AS2=TRANSPOSE(X9:AB15)
AS7:AY7AS7=((AS6-AS3)-(AS5-AS4))*24
AS9:AY9AS9=SUM(AS13:AS31)
AS10:AY10AS10=SUM(AS13:AS36)
AN13:AO36AN13=$AM$11+AP13
AS13:AY36AS13=((IF(AS$4>$AN13,AS$4-$AN13,0)-IF(AS$3>$AN13,AS$3-$AN13,0))-(IF(AS$4>$AO13,AS$4-$AO13,0)-IF(AS$3>$AO13,AS$3-$AO13,0)))*24 + ((IF(AS$6>$AN13,AS$6-$AN13,0)-IF(AS$5>$AN13,AS$5-$AN13,0))-(IF(AS$6>$AO13,AS$6-$AO13,0)-IF(AS$5>$AO13,AS$5-$AO13,0)))*24
Dynamic array formulas.
I will give this a try and let you know if it worked. Thank you soooo much!!
 
Upvote 0
Sounds good...let me know if you run into any difficulties or discover any unexpected results. Also...be aware that when you enter the TRANSPOSE function in AS2, you will probably need to enter it with Ctrl-Shift-Enter, which makes it an array formula. If a formula is already entered normally and you want to convert it to an array formula, select the cell where the formula is found, click on the formula in the formula bar, hit F2 to go into edit mode, then simultaneously hit Ctrl-Shift-Enter. You should see curly brackets automatically inserted around the formula.
 
Upvote 0
Sounds good...let me know if you run into any difficulties or discover any unexpected results. Also...be aware that when you enter the TRANSPOSE function in AS2, you will probably need to enter it with Ctrl-Shift-Enter, which makes it an array formula. If a formula is already entered normally and you want to convert it to an array formula, select the cell where the formula is found, click on the formula in the formula bar, hit F2 to go into edit mode, then simultaneously hit Ctrl-Shift-Enter. You should see curly brackets automatically inserted around the for
 
Upvote 0
This seems to be working perfectly! I have been working on this for a looong time with different approaches. I really appreciate your help. You are awesome.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top