Unsocial Hours Time Sheet Calculations

aproberts1980

New Member
Joined
Jul 14, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
I am trying to build a sheet to calculate unsocial hours pay from a timesheet. The criteria for the unsocial hours is as follows:

Monday - Friday 0700-2000 - No enhancement
Monday - Friday 1900-0700 - 44%
Saturday - 0700-0700 Sunday 44%
Sunday - 0700-0700 Monday 88%

example -

Mon - Fri 07:00-19:00 would pay 12 hrs standard
Mon - Fri 15:00 - 23:00 would pay 5 hrs standard and 3 hrs +44%
Mon - Fri 19:00-07:00 would pay 12 hrs +44%
Saturday 07:00-19:00 would pay 12 hrs +44%
Sunday 07:00-19:00 would pay 12 hrs +88%

Up to and including the hours column we have as core data so it is just the forumla needed to read to hours into the relevant category that is needed

LocationNameDateStartEndHoursStandard44%88%
test1subject114/07/202015:0023:008530
test1subject214/07/202019:0007:00120120
test1subject318/07/202007:0019:00120120
test1subject419/07/202019:0007:00120012

Any help that could be given would be appreciated.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to MrExcel!

A quite tricky problem, which is why no one's answered yet. Here's my stab at it:

Book1
ABCDEFGHIJKLMNOPQ
1StartEndTypeLocationNameDateStartEndHoursStdRate44Rate88StartEnd
2Sunday 0:0000.291667Rate88test1subject114-Jul15:0023:0084402.6252.958333333
3Sunday 7:000.2916670.791667Rate88test1subject214-Jul19:007:001201202.7916666673.291666667
4Sunday 19:000.7916671.291667Rate88test1subject318-Jul7:0019:001201206.2916666676.791666667
5Monday 7:001.2916671.791667Stdtest1subject419-Jul19:007:001200120.7916666671.291666667
6Monday 19:001.7916672.291667Rate44test2subject513-Jul0:0010:001030711.416666667
7Tuesday 7:002.2916672.791667Stdtest2subject613-Jul5:0020:4515.75121.7521.2083333331.864583333
8Tuesday 19:002.7916673.291667Rate44
9Wednesday 7:003.2916673.791667Std
10Wednesday 19:003.7916674.291667Rate44
11Thursday 7:004.2916674.791667Std
12Thursday 19:004.7916675.291667Rate44
13Friday 7:005.2916675.791667Std
14Friday 19:005.7916676.291667Rate44
15Saturday 7:006.2916676.791667Rate44
16Saturday 19:006.7916677.291667Rate44
17Sunday 7:007.2916677.791667Rate88
18Sunday 19:007.7916678.291667Rate88
19Monday 7:008.2916678.791667Std
Sheet6
Cell Formulas
RangeFormula
C2C2=7/24
K2:K7K2=(IF(J2<I2,J2+1,J2)-I2)*24
L2:N7L2=ROUND(SUM(IF($D$2:$D$19=L$1,IFERROR(EXP(LN(IF($Q2<$C$2:$C$19,$Q2,$C$2:$C$19)-IF($P2>$B$2:$B$19,$P2,$B$2:$B$19))),0)))*24,2)
P2:P7P2=WEEKDAY(H2)-1+I2
Q2:Q7Q2=P2+K2/24
B3:B19B3=C2
C3:C19C3=B3+0.5
Press CTRL+SHIFT+ENTER to enter array formulas.


First you'll note the table on the left. You can put this anywhere, even on another sheet. It has the time ranges for the whole week, the start time, end time, and type. Since the ranges were all 12 hours apart, I just entered the first 2 manually, and used formulas the rest of the way down. Note that Sunday is day 0 in this scheme, and each day goes up by 1. Also note that your table as you described it overlaps. For weeknights, the normal range ends at 20:00, but the 44% range starts at 19:00. You may need to adjust the table to whatever that hour really is, and you might need to do it manually.

Next, look at columns P and Q. These convert the start and end times from the H/I/J columns into the ranges that match the table. You can hide these columns, or if you want we can incorporate them into the final formula and get rid of them. But it was easier to test with them like this, and it keeps the final formula shorter.

Finally the L2 formula should do what you want. Put it in L2, then copy to the rest of the L2:N7 range. The headings in L1:N1 can be whatever you want, they just have to match column D. Note that in this example L2 and M2 are different from your expected values, but that's due to the 19:00/20:00 issue I just mentioned. This also assumes no one will have a shift over 24 hours. If so, enter it in 2 pieces.

Take a look and see if this might work for you!
 
Upvote 0
Thanks for this, it is really appreciated. The main concept makes sense but the big formula when copied to excel returns 0. I have attached an image below. formula below is taken from L2.

=ROUND(SUM(IF($D$2:$D$19=L$1,IFERROR(EXP(LN(IF($Q2<$C$2:$C$19,$Q2,$C$2:$C$19)-IF($P2>$B$2:$B$19,$P2,$B$2:$B$19))),0)))*24,2)

Also if there was a time change in the criteria of when the allowance starts and ends do I just change this in the left table?

Thanks again for you help.

1594770259342.png
 
Upvote 0
Nice job, Eric. I had begun to make a similar mapping of time blocks over an entire week, but I hadn't yet sorted out the complete cycle..

Regarding your questions @aproberts1980, did you enter the L2 formula as an array formula (confirmed with Ctrl-Shift-Enter)? The time blocks would be edited in columns A, B, C, and D.
 
Upvote 0
Hi aproberts1980,

I think Kirk is right when he said that you need to enter the formula as an array formula. If you're not familiar with array formulas, after you enter the formula in the formula bar, hold down the Control and Shift keys, then press Enter. Once you do that, you can copy it and paste it like a normal formula.

He's also correct about editing the table. Just change the start and end times as needed. There's no reason that each range is exactly 12 hours, they can be longer or shorter, just make sure that the ranges do not overlap. If you need to add or remove some lines, you can, you just need to update the ranges in the big formula.

Another thing! You're new here, so you're probably not familiar with the tool I used to post my screen print. It's called XL2BB, and you can get a copy by clicking on the XL2BB button in the response box, or my signature. It makes it much easier for someone to look at your spreadsheet. But even if you don't have it, it's got a feature that you can use. Look at post #2 where I put my screen print:

1594784578643.png


If you click on the icon I circled, it will copy the sheet to the clipboard. If you then go to a blank Excel sheet and click Paste, it will copy the whole thing, including formatting and formulas to your sheet. I looked at your regular screen print in post 3 and thought "I hope he didn't have to type all that!". The exception is array formulas. It will copy the main formula, but you still have to edit the formula again to add the Control+Shift+Enter.

Anyway, let us know if you have any more questions! :biggrin:
 
Last edited:
Upvote 0
If you require this to be solved by worksheet functions, it is fairly tricky.
If you allow VBA, I have seen at least two obviously well tested functions on the web.
Problem is, in contrast to German speaking forums the English speaking ones (I know of) do not allow links.
 
Upvote 0
Problem is, in contrast to German speaking forums the English speaking ones (I know of) do not allow links.
Do you mean against the rules to post links or technically can't post the links.
but you still have to edit the formula again to add the Control+Shift+Delete.
@Eric W, I think that you made a typo in post #5 and meant Control+Shift+Enter in the line above (it is correct earlier in the post).
 
Last edited:
Upvote 0
The rules do not allow it.
That is not 100% accurate, the rules state
1594814273423.png

So if it is an article then sometimes they are acceptable. If unsure it can always be checked with a Moderator whether a particular link is allowable or not.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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