How can I calculate hours worked on a project using specific working hours that aren't the same each day?
So Monday - Friday I work 7 am-7 pm, Saturday 9 am -1 pm and I take Sunday off (lucky me). If i start a project on the 1st March 10 am and finish on the 5th March at 9 am how can I calculate an answer of 27 hours ??
I have two cells date/time start and date/time finish. I have multiple rows to do this to and several time points but this essentially will work the same.
I hope makes sense.
Edit - Solutions tried and opposing results
You will need a helper column with this formula:
=24*(SUMPRODUCT((TEXT(ROW(INDEX(AAA:AAA,$F$1):INDEX(AAA:AAA,$F$2)),"dddd")=A1)*(C1-B1))-IF(TEXT($F$1,"dddd")=A1,MOD($F$1,1)-B1,0)-IF(TEXT($F$2,"dddd")=A1,C1-MOD($F$2,1),0))
Then sum that column.
Here it is in one formula using NETWORKDAYS.INTL
=IF(DATEDIF(F1,F2,"d")>1,NETWORKDAYS.INTL(F1+1,F2-1,"0000011")*12+NETWORKDAYS.INTL(F1+1,F2-1,"1111101")*4,0)+IF(DATEDIF(F1,F2,"d")>0,(MOD(F2,1)-IF(WEEKDAY(F2,2)<6,TIME(7,0,0),TIME(9,0,0)))*24+(IF(WEEKDAY(F1,2)<6,TIME(19,0,0),TIME(13,0,0))-MOD(F1,1))*24,(F2-F1)*24)
Related
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!
I'm trying to get the week number of a given quarter based on the date.
I currently have this formula
=1+(WEEKNUM(EDATE(Y4,-1)))-(WEEKNUM(DATE(YEAR(EDATE(Y4,-1)),
LOOKUP(MONTH(EDATE(Y4,-1)),{1,4,7,10}),1)))
But for January, it should be giving me 1 but it's giving me 10. Any suggestions?
How do you expect this to work at the start and end of the quarter? Default WEEKNUM function starts week 1 on the 1st of January every year and week 2 starts on the next Sunday after 1st January.
Assuming your quarter week numbers should work the same way, i.e. week 1 starts on the 1st of Jan/Apr/Jul/Oct and week 2 starts on the next Sunday then that's actually equivalent to counting Sundays since 6 days back into the previous quarter.
You can do that using NETWORKDAYS.INTL function, i.e. with this formula:
=NETWORKDAYS.INTL(EOMONTH(Y4,MOD(1-MONTH(Y4),-3)-1)-5,Y4,"1111110")
format result as number with no decimal places
NETWORKDAYS.INTL function is available in Excel 2010 and later versions - for older versions of Excel you can get the same results with this formula:
=INT((13-WEEKDAY(Y4)+Y4-EOMONTH(Y4,MOD(1-MONTH(Y4),-3)-1))/7)
(Expanded from comment)
when you choose a date in January, it's going back to December. 12 in your lookup array gives 10 as the result. Perhaps instead of EDATE, you should use EOMONTH(Y4,-1)+1, so you look at the 1st of the current month for your calculation
=1+(WEEKNUM(EOMONTH(Y4,-1)+1))-(WEEKNUM(DATE(YEAR(EOMONTH(Y4,-1)+1), LOOKUP(MONTH(EOMONTH(Y4,-1)+1),{1,4,7,10}),1)))
This is fairly interesting, since it changes with the year, and changes with what day of the week is the "start" of the week. So if a quarter starts on Saturday, and the week starts on a Saturday, the entire week is week 1. However, if it starts on a Sunday, week 1 is only one day long, and week 2 starts on Sunday.
The first question we have is, what day is it?
=DayCheck
Additionally, I'm going to call the start of each quarter the following:
Q1Start = Date(Year(DayCheck),1,1)
Q2Start = Date(Year(DayCheck),4,1)
Q3Start = Date(Year(DayCheck),7,1)
Q4Start = Date(Year(DayCheck),10,1)
The next question is, what's the first day of the week? We have some control over this with the Weekday function. For the sake of keeping it simple, Sunday is the start of the week.
Ok, that's our day. Next, what quarter is it?
`Quarter=ROUNDDOWN(MONTH(O16)/4,0)+1`
This gives us 1 for Q1, 2 for Q2, etc.
What day of the week is it now?
=WEEKDAY(DayCheck,1)
Ok, and now, what week are we on?
=WEEKNUM(DayCheck,1)
I'm going to put it together in a not very elegant fashion. I'm sure there's a better way out there.
=(Quarter=1)*((Weeknum(DayCheck)-WeekNum(Q1Start)+1)+(Quarter=2)*((Weeknum(DayCheck)-WeekNum(Q2Start)+1)+(Quarter=3)*((Weeknum(DayCheck)-WeekNum(Q3Start)+1)+(Quarter=4)*((Weeknum(DayCheck)-WeekNum(Q4Start)+1)
Try this:
=CHOOSE((MOD(WEEKNUM(Y4),13)=0)+1,WEEKNUM(Y4)-(ROUNDDOWN(WEEKNUM(Y4)/13,0)*13),13)
This will get the week number of a given date within a quarter.
I used this in one of my applications so you might be able to use it too. HTH.
Note: If you use 1st day other than Sunday, then adjust the WEEKNUM formula.
Can try this as I got this as combination of 2 formula
=WEEKNUM(A1,1)-(INT((MONTH(A1)-1)/3)*13)
second part - INT((MONTH(A1)-1)/3) gives us the quarter number of previous quarter which then multiplied with 13 weeks/quarter gives us how many weeks have passed in all previous quarter before current quarter.
First part - "WEEKNUM(A1,1)" gives us the week number of current week in the year.
so by deducting all the previous weeks in previous quarters from current week number of year, we get the current week number in current quarter.
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.
I apologize if this has been answered elsewhere, but I have searched the other week number answers and haven't found a solution that works for multiple years.
The tire industry calculates week numbers starting with the first full week that begins on a Sunday. For example, in 2016 Week 1 commenced with 3 January. In 2017, Week 1 will begin on Sunday, 1 January. In 2018 Week 1 will start with Sunday, 3 January.
In Excel 2010, using returns type 1 and 17 (week starting on Sunday), 1 January for all three years is Week 1 when that should only be correct for 2017. It should return Week 201552 for 2016 and 201653 for 2018
I have tried the examples posted in other answers and also checked Ron de Bruin's page with his formulas for calculating the week number, but I've been unable to modify it correctly to get the formula to work consistently.
Here is Ron's example for calculating ISO week numbers:
=INT((B4-DATE(YEAR(B4-WEEKDAY(B4-1)+4),1,3)+WEEKDAY(DATE(YEAR(B4-WEEKDAY(B4-1)+4),1,3))+5)/7)
Thanks in advance for any suggestions or guidance.
You can use this formula:
=IFERROR(YEAR(B4) &TEXT(INT(DATEDIF(DATE(YEAR(B4),1,AGGREGATE(15,6,{1,2,3,4,5,6,7}/(WEEKDAY(DATE(YEAR(B4),1,{1,2,3,4,5,6,7}))=1),1)),B4,"d")/7)+1,"00"),YEAR(B4)-1 &TEXT(INT(DATEDIF(DATE(YEAR(B4)-1,1,AGGREGATE(15,6,{1,2,3,4,5,6,7}/(WEEKDAY(DATE(YEAR(B4)-1,1,{1,2,3,4,5,6,7}))=1),1)),B4,"d")/7)+1,"00"))
I see this question has been answered way back but for future reference.....
I have previously posted formulas which give ISO week number - see here ...and that formula can be adjusted depending on how the start day or date is defined, so to get the YEAR&WEEKNUMBER for a date in A2 where week 1 starts on the first Sunday of the year you can use this formula
=YEAR(A2+1-WEEKDAY(A2))&TEXT(INT((A2-WEEKDAY(A2)-DATE(YEAR(A2+1-WEEKDAY(A2)),1,7))/7)+2,"00")
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.