how to do 2 seperate operations if start time of shift is before 7 but end time is after 7 - excel

I'm trying to make an excel sheet where I only need to put in start and end time and excel chooses the correct pay rate and how many hours I've worked (already done) and outputs how much I've earned. So far I have a column (D) for the date of shift (DAY, day of month, Month, year) column for hours worked (E), column for start time and end time (F, G) I have already written the formula to calculate the hours worked but in Australia where I live my pay rate increases after 7 PM, and increases again after 12 AM. Is there a way to have excel automatically know that it needs to take the hours worked before 7 PM and multiply it by a 24.41, then the hours worked between 7 PM and 12 AM by 26.54 etc, if my shift starts for example at 5:30 pm and ends at 3 AM?
These are the different payrates at the different times: (Time is in cell A1, Pay rate is B1, etc)
Time Pay Rate
Regular $24.41
Mon-Fri 7pm-midnight $26.54
Mon-Fri 7midnight-7am $27.60
Saturday $29.30
Sunday $34.18
Public Holidays $48.83
Thanks in advance

Solutions to all of these type of questions use the standard formula for overlapping time periods
=max(0,min(end1,end2)-max(start1,start2))
The best way to do it IMO is to simplify it two ways
(1) By splitting any times that cross through midnight into two parts, one up to midnight and one from midnight onwards
(2) Using a lookup table to match the conditions (day of week and time of day) to the payscale.
Then use an array formula to do the lookup and calculation. Because you can't use MAX and MIN as above in an array formula, you have to write it out using if statements and the formula gets pretty long
=SUM((WEEKDAY(E2,2)>=PayRates!$A$2:$A$10)*(WEEKDAY(E2,2)<=PayRates!$B$2:$B$10)*24*PayRates!$E$2:$E$10*
IF(IF(G2<PayRates!$D$2:$D$10,G2,PayRates!$D$2:$D$10)-IF(F2>PayRates!$C$2:$C$10,F2,PayRates!$C$2:$C$10)<0,0,
IF(G2<PayRates!$D$2:$D$10,G2,PayRates!$D$2:$D$10)-IF(F2>PayRates!$C$2:$C$10,F2,PayRates!$C$2:$C$10)))
This has to be entered using CtrlShiftEnter
This is how my pay rates are arranged
NB When the finishing time of a pay rate is midnight, it is entered as 1 (you want it to be 24:00, but entering 24:00 just gives you the same as 00:00)
And this is the main sheet
With the following columns
A,B and C are your input.
Split
=B2<A2
StartDate1 and StartTime1 are just a copy of your input
EndTime1
=IF(Split,1,B2)
StartDate2
=E2+Split
StartTime2
00:00
EndTime2
=IF(Split,B2,0)
Total1
The main formula
Total2
The main formula copied across by four columns to give any pay for the second day when the shift goes through midnight.
Total
Total1+Total2
Public holidays can be added fairly easily.

Related

Excel Date difference without weekend days

Last time I posted a quite vague story about a date difference challenge which I haven't solved yet. I will try to elaborate since I have tried everything in my power and the problem still isn't fixed.
I currently have three columns.
Column 1 (F)
the date a car starts its repairs (format DayOfWeek-DD-MM-YYYY)
Column 2 (G)
the number of days in which the car is repaired (service level agreement [SLA]; the standard is 10 days)
Column 3 (H)
the output, which is the date the car should be finished. So the number of days after the startdate*
*Th thing which makes this case difficult is that only weekdays are included.
So, for example:
If a car starts repairs on Monday 1st of August, the finish date is Tuesday the 14th of August.
I tried to solve this with the following formula:
=IF(WEEKDAY(F218)=2;(F218+11);
IF(WEEKDAY(F218)=3;F218+12;
IF(WEEKDAY(F218)=4;F218+13;
IF(WEEKDAY(F218)=5;F218+14;
IF(WEEKDAY(F218)=6;F218+15)))))
In other words:
If startdate = Monday then startdate + 11,
if startdate = Tuesday then startdate + 12, etc.
This works, but I have 300+ rows and dragging this function down doesn't change the cell references.
I know about the NETWORKDAYS and WEEKDAY functions, but I encounter problems with any Monday where only 1 weekend passes and other days where 2 weekends pass.
First of all, I am assuming that your first day - whatever day that may be - is considered day one (1). So in my scenario, if a SLA states 2 days to complete a repair and the start date is a Monday, I'm assuming the repair should be completed by Tuesday.
My assumption is based off this comment by #RonRosenfeld:
...although you might have to subtract 1 from the number of days
With all that being said, try this formula in your cell instead:
 NOTE: You may need to change things like commas and semi-colons to adjust for your region.
=WORKDAY($F2,$G2-1)+LOOKUP(WEEKDAY(WORKDAY($F2,$G2-1),16),{1;2;3},{2;1;0})
What it does:
WORKDAY($F2,$G2-1)
First we want to find out exactly what day the repairs should be completed by if weekend days (Saturday and Sunday) were included. This part of the formula will simply give us a place to start.
$F2 is your repair start date
$G2 is the number of days a repair is supposed to take (you may need to add a column for this, because, as you stated, the SLA may change and you need the formula to be easily adjusted)
WEEKDAY(WORKDAY($F2,$G2-1),16)
The WORKDAY function from above is wrapped inside a WEEKDAY function. This WEEKDAY function is written to account for each day of a week to be assigned numbers. The [return_type] parameter of 16 tells Excel to label them as "Numbers 1 (Saturday) through 7 (Friday)". We chose 16 so that our LOOKUP function is easier to write. This part of the formula only returns a one-digit number, which in turn will be used to figure out what day of the week we actually want when excluding weekends.
LOOKUP(WEEKDAY(WORKDAY($F2,$G2-1),16),{1;2;3},{2;1;0})
We finish the formula by adding the result from a LOOKUP function using the first form of the function: LOOKUP(lookup_value,lookup_vector,[result_vector])
We found our lookup_value in the previous bullet point using the WEEKDAY function. Now we want Excel to use the lookup_vector - {1;2;3} in our formula - to find the correct value to add to the first part of our formula (which is found using the [result_vector] - {2;1;0} in our formula).
The lookup_vector only has three values: 1, 2, and 3.
1 signals Saturday
2 signals Sunday
3 signals all other days
Think of the lookup_vector and [result_vector] as forming a matrix/table from which our value is found:
1   2
2   1
3   0
If our number of repair days pushes us to:
a Saturday (1), the formula adds 2.
a Sunday (2), the formula adds 1.
any weekday, the formula adds 0 (since weekdays are acceptable).
Hopefully all of this makes sense. Best of luck to you!

Count number of hours between 2 dates excluding weekends and between 10pm - 10am?

I'm trying to calculate the number of hours between two date/times, excluding bank holidays and between 10pm and 10am.
I've got the Start Datetime in B3, and then End Datetime in G3. In SLA B13 - B22, I have a list of the bank holiday dates for 2015, and I am using the following forumal
=SUM(G3-B3-COUNTIFS(SLA!B13:B22,">"&B3,SLA!B13:B22,"<"&G3))
For some reason, I cant get this to exclude bank holidays, however I then also nee to take into account the 10pm - 10am bracket.
Can anyone help?
=NETWORKDAYS(B3;G3;SLA!B13:B22)*12
*12 because only 12 hours per day count (exclude time between 10 pm and 10 am)
I've tried your formula and it works fine for whole days for me, as long as you format the cell containing the formula as general or number to avoid formatting it as a date. It doesn't exclude weekends of course which presumably is what you want.
You might want to add 1 to make it inclusive, make > into >= and < into <= in case the start and end dates are bank holidays and multiply by 12 to get the result in hours:-
=(G3-B3+1-COUNTIFS(SLA!B13:B22,">="&B3,SLA!B13:B22,"<="&G3))*12
You could calculate the hours worked directly from datetime values: the basic formula would be:-
=(G3-B3)*24-(INT(G3)-INT(B3))*12
i.e. subtracting 12 hours for each complete day.
You could also exclude the holidays (if between the start and end dates):-
=(G3-B3)*24-(INT(G3)-INT(B3)+COUNTIFS(SLA!B13:B22,">"&B3,SLA!B13:B22,"<"&G3))*12
i.e. subtracting a further 12 hours for each day's holiday.
One more thing you could do is to apply an adjustment for start and end time to the Networkdays formula by adding:-
=MOD(G3,1)-MOD(B3,1)

Excel function to create due dates that land on a business day

I'm stuck creating a formula that will calculate days before the end of the month then adjust to make sure it is a business day. For example: 30 days before 6/30/2015 is 5/31/2015 which is a Sunday. I need that to adjust to the Friday before.
I'm working on finding the due dates of a number of documents that are due a certain number of days before another date. For example: documents are due 30 days before the last day of the month. However, the number of days varies and the due date needs to fall on a business day (Monday-Friday). Sometimes it's 30 days, sometimes it's 60 days, sometimes it's 30 calendar days + 5 business days, etc.
I've been able to calculate 30 days + 5 business days with the following formula:
=workday(start_date-30,-5)
Any ideas how to adjust this so that I can just have the due date be 30 calendar days before a certain date but also always be a business day?
Using WORKDAY you can use a formula like this:
=WORKDAY(A1+B1+1,-1)
where A1 is your start date and B1 the number of days to add.
You probably need to write a macro function or maybe some nested IF statements in your cell's formula.
Take a look at http://www.mrexcel.com/forum/excel-questions/481558-round-date-nearest-workday.html
That solution moves forward to the nearest workday, but the principle is sound: just subtract instead of add.

Excel how get number of hours in a time interval?

I have 2 columns with:
Night shift start: 19:00
Night end: 04:00
And I have some date columns with for each day..
Work started: 07:30
Worked ended: 22:00
I want to get the number of hours as a decimal that is between the night shift start and night end. I need to calculate the number of "night shift hours" for worked hours.
From comment: I do not want to get the total number of hours. I want to calculate the number of "night shift hours" and that is hours between 19:00-04:00
=IF(B1-A1 < 0, 1-(A1-B1),( B1-A1))
Assuming that cell A1 contains start, B1 contains end time.
Let me know, if it helps OR errors.
Time without date is not enough to do the subtraction considering the start can be the night before today.
Are you OK to try VBA?
EDIT: The formula is meaningful within 12 hour limit. I will see if it can be made simpler.
Given start time in B5 and end time in C5 this formula will give you the decimal number of hours that fall in the range 19:00 to 04:00
=MOD(C5-B5,1)*24-(C5<B5)*(19-4)-MEDIAN(C5*24,4,19)+MEDIAN(B5*24,4,19)
format result cell as number
just substract the two dates to get the difference in days, and multiply by 24 to get the difference in hours
=(B1-A1)*24
this is correct when both B1 and A1 contain a datetime value, but in case your cells contain just a time value, with no day value, and given that the calculation spans the night (there is a day change in between) you need to add one day to the difference:
=IF(B1<A1,1+B1-A1,B1-A1)*24

Elapsed Days Hours Minutes Excluding Weekends and Holidays Time

This sounds simple but I have been pulling my hair out trying to figure out a solution. Any help before I go bald would be great.
I need a formula which is able to
calculate the duration in (days, hrs, mins) between two date\time values (eg 05/12/2012 5:30 PM and say 07/12/2012 5:45 PM);
excluding weekends and holidays.
I would like the result of the formula to read as follows "e.g 2 Days 0 Hrs and 15 Mins".
Thanks
Link to sample workbook
You can use NETWORKDAYS and NETWORKDAYS.INTL to achieve this
A bit of manipulation is required as these return net whole days:
Use these functions to calculate the number of non workdays, then subtract from the difference between start and end dates
=E3-D3-(NETWORKDAYS.INTL(D3,E3,"0000000")-NETWORKDAYS(D3,E3,$A$16:$A$24))
This returns the working day difference, where 1.0 = 1 day
NETWORKDAYS.INTL(D3,E3,"0000000") calculates whole days between the two dates (no weekends, no holidays)
NETWORKDAYS(D3,E3,"0000000",$A$16:$A$24) calculates whole working days days between the two dates (Sat/Sun weekends, holidays as per your list in $A$16:$A$24)
Difference in non-working days between the two dates.
E3-D3 is time between start and end date/times (1.0 = 1 day)
Use custom number formatting to display thye result in the format you require
d "Days" h "Hours" mm "Mins"
Note: this format won't work for negative values, you will need an alternative for when end date is before start date.
The following formula works like a treat with no additional formatting or manipulation.
To make it more stable I have turned all the holiday dates for UK 2012/13 into ‘Excel Serial Number’ format and placed them in an array bracket.
Replacing the "D5" in the formula with your cell reference for your course or metric "End Date" and "E5" with your course or Metric for "Completion Date".
=IF(E5<D5,"-"&TEXT(D5-E5,"h:mm"),NETWORKDAYS(D5,E5,({40910,41005,41008,41036,41064,41065,41148,41268,41269,41275,41362,41365,41400,41421,41512,41633,41634}))-1-(MOD(E5,1)<MOD(D5,1))&" days "&TEXT(E5-D5,"h:mm"))

Resources