I'm trying to find out if someone was not working during 'out of hours'.
If Monday to Friday, not between the hours of, 8am to 9pm, then the answer would be "Yes"
If it's a Saturday, not between the hours of, 8am to 5pm, the answer
would be "Yes"
If it's a Sunday, not between the hours of, 9am to 5pm, the answer
would be "Yes".
Otherwise the answer would be "No".
There are 4 columns: 1. Person's Name (A) 2. Date (B) 3. Time (C) 4. Out of Hours (D)
I've copied in the formula below which is working correctly for Monday to Friday, but I'm struggling with the second part of the weekend one.
=IF(OR(WEEKDAY(B2)=1,WEEKDAY(B2)=7),"Yes",IF(AND(C2>=8/24,C2<21/24),"No","Yes"))
If anyone could advise on how to change the formula to work with 'out of hours' for Saturday and Sunday?
It would be greatly appreciated.
Since your WEEKDAY(B2) will be from 1 (Sunday) to 7 (Saturday), you can use CHOOSE to select the Start/End time for your "In-Hours" period:
Start: =Choose(Weekday(B2),9,8,8,8,8,8,8)
End: =Choose(Weekday(B2),17,21,21,21,21,21,17)
So, if HOUR(C2) is >= Start, and HOUR(C2) is < End then you are "In-Hours" ("No"), otherwise you are "Out of Hours" ("Yes")
=IF(AND(HOUR(C2)>=CHOOSE(WEEKDAY(B2),9,8,8,8,8,8,8), HOUR(C2)<CHOOSE(WEEKDAY(B2),17,21,21,21,21,21,17)),"No","Yes")
Of course, I would recommend replacing the CHOOSEs with a pair of VLOOKUPs, and having a hidden sheet where you list the Weekday and the Start/End-of-Hours hours. (Much easier to update if The Boss decides to change the hours!)
=IF(WEEKDAY(B2)=7,IF(OR(C2<TIMEVALUE("8:00"),C2>TIMEVALUE("17:00"))=TRUE,"Yes","No"),IF(WEEKDAY(B2)=1,IF(OR(C2<TIMEVALUE("9:00"),C2>TIMEVALUE("17:00"))=TRUE,"Yes","No"),IF(WEEKDAY(B2)<>1,IF(OR(C2<TIMEVALUE("8:00"),C2>TIMEVALUE("21:00"))=TRUE,"Yes","No"),"No")))
You will have to use nested ifs. Hope above formula will work.
Related
I made a worksheet covering meal expenses for a set period of time (01-08-2020 until 31-08-2020.)
The company will pay up to 75kr, Monday-Friday.
The list covers expenses 7 days a week, If the amount is greater than 75 on Monday-Friday, I have to pay the extra expenses. (This I have figured out correctly). Saturday and Sunday I have to pay fully.
So my question is, how can I sum this and exclude Saturday and Sunday?
Attempt 1:
I tried this formula (Norwegian excel. Summerhvis = SUMIF. Lørdag = Saturday):
=SUMMERHVIS(B2:B32,"<>lørdag", G2:G32)
It seems to be partly correct however, I miss Sunday, how can I add Sunday to this equation?
Attempt 2:
I used this formula:
=SUMMERHVIS(B2:B32,B2:B6,G2:G32)
It gave the correct answer but the answer was layered in 5 rows. I then summed this in P8.
Where I want the answer is in G32. So in G32 I wrote =p8.
It must be an easier way of doing this?
You can use SUMPRODUCT and the WEEKDAY function:
=SUMPRODUCT((WEEKDAY(A2:A32,3)<5)*G2:G32)
According to the Microsoft function translator, this might be, in Norwegian:
=SUMMERPRODUKT((UKEDAG(A2:A32;3)<5)*G2:G32)
If you really want to use SUMIF and your text days, one way would be (in English):
=SUM(SUMIF(B2:B32,{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday"},G2:G32)),
or, if your weekday days are in b4:b8:
=SUM(SUMIF(B2:B32,$B$4:$B$8,G2:G32))
but I'd advise against it as it would only work in the language of the text days of the week. Also, I note your days of the week don't seem to match up with what the days of the week were in the US. For example, here 1 Aug 2020 was a Saturday, so another possible cause for error (unless I am not understanding the dates correctly).
The above is the same as summing five separate SUMIF equations, each for a desired day of the week.
I have a formula to calculate the first Friday of the Year and it works okay.
I understand how the formula gets the answer however, I can't seem to find the reasoning behind the formula. The formula is:
=DATE(YEAR(TODAY()),1,8)-WEEKDAY(DATE(YEAR(TODAY()),1,2))
This gives us 2020/01/08 - 5 = 2020/01/03 which is the First Friday of the Year. But why does the formula choose 8 and 2 as the dates?
Can someone please explain the reason.
The first, obvious, part of the formula is that DATE(YEAR(TODAY()),1,8) gives you the eighth day of the month which can't be the first Friday since one of the 7 days before it would must be a Friday.
My guess is that the second part has a little bit of kludgery going on. WEEKDAY(DATE(YEAR(TODAY()),1,1)) would give you the number of days from the first day of the month to the previous Sunday. But if you're looking for the previous Saturday you'd need WEEKDAY(DATE(YEAR(TODAY()),1,1)) + 1 or WEEKDAY(DATE(YEAR(TODAY()),1,2)).
Finally, the day of the week WEEKDAY(DATE(YEAR(TODAY()),1,2)) before the 1st of the month is the same day of the week before the 8th of the month.
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 am trying to check if a date falls within the upcoming week.
For example, today is 9/14/2016.
The upcoming week is defined as anything that are through 9/23/2016.
I was wondering if anyone can help me with it. Thanks.
Assuming standard convention for the week is in line with Excels, (Sunday through Saturday):
=IF(AND(A1 >= TODAY(),A1 <= TODAY() + 6 + WEEKDAY(A1)),TRUE,FALSE)
This will return TRUE if the value in A1 is within the upcoming week and false if it is not.
I can see that 9/23/2016 is a Friday but I wasn't sure what you wanted to do if it was currently Sunday (say) and you wanted to see if a date was on or before Friday in the upcoming week - would that be Friday 5 days later or 12 days later? So I've done an answer that can be tailored however you want it:-
=AND(D$2>=$A3,D$2<=$A3+CHOOSE(WEEKDAY($A3),5,11,10,9,8,7,6))
where A3 contains the current date and D2 contains the date you're trying to evaluate.
So the numbers in the choose statement say what you want to do with each day:-
If Sunday add 5 days
If Monday add 11 days
etc. etc.
See also