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.
I am trying to calculate the weeks of the month, 1-4 or 1-5, where the calendar week that contains the first calendar day of the month is always week 1. So for example, February 1, 2018 falls on a Thursday so the dates Monday January 29 - Sunday February 4 would be week one of February.
I was using the formula =INT((DAY(D2)+6)/7) - which seemed to work until the week splits and crosses the calendar month. It counted the days the cross over from January as week 5 rather than week 1 of the next month.
Try this and see if it works:
=IF(MONTH(A2)=MONTH(A2+7-WEEKDAY(A2,2)),CEILING(((DAY(A2)+WEEKDAY(A2-DAY(A2)-1)))/7,1),1)-AND((WEEKDAY(A2-DAY(A2))=1),MONTH(A2)=MONTH(A2+7-WEEKDAY(A2,2)))
Is the following Sunday in the same month as the Date (in A2)
If False, Week = 1
If True
use last Sunday of preceding month as base for week count.
Adjust if month starts on a Monday and we are in the first week (there's possibly a better way to do this adjustment)
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.
how to add new column having week number i.e should consider sunday - saturday as 1 , next sunday - saturday as 2 in an daywise data.
Thanks in advance
Week([DateColumn]) will get you the respective week number. This resets for each year.
I need to be able to enter a date that will count back 14 days and show the next Monday e.g. enter 25/12/2015 and get a return of 15/12/2015, however at the same time if I enter a date that happens to be a Monday it will only count back 7 days e.g. enter 15/12/2015 and get 08/12/2015 February. Tried using this formula but anytime i enter a date that is a Sunday it skips forward to the upcoming Monday...!!??!
=IF(WEEKDAY(D4)<2,D4+2-WEEKDAY(D4),D4+2-7-WEEKDAY(D4))
Thanks everyone
This works too. The problem is that Sunday has a lower weekday value than Monday. Mod 7 solves that problem.
=(D4-7)-MOD(WEEKDAY(D4)-2,7)
You mean the Monday 14th December Monday 7th December right?
=CEILING(IF(WEEKDAY(D4,3)=0,D4-7,D4-14)-2,7)+2
As a breakdown - I used Jon von der Heydens formula here: http://www.mrexcel.com/forum/excel-questions/468174-formula-find-next-monday.html.
=CEILING(A1-2,7)+2 returns the following Monday date to the date in A1.
So using IF and the WEEKDAY formula: if the date is a Monday remove 7 days, otherwise remove 14 days and find the following Monday to that date.