Excel weeknum function showing wrong week number? - excel

I have a workbook:
Column A Column B
01/01/2017 =WEEKNUM(A2,2)
26/01/2017 =WEEKNUM(A3,2)
I am trying to get the week number starting monday.
Excel gives me this:
01/01/2017 1
26/01/2017 1
Both dates cannot have a week number of 1. What am i doing wrong?

I encountered the same concern and stumbled on this thread too (Microsoft Excel Online).
For this case, ISOWEEKNUM worked for me, please note that I've set my date settings to English (United Stated).

As long as there is no precise answer for this post, I would like to mention that your issue is all documented in WEEKNUM.
There are two systems used for this function:
System 1 The week containing January 1 is the first week of the
year, and is numbered week 1.
System 2 The week containing the first Thursday of the year is the
first week of the year, and is numbered as week 1. This system is the
methodology specified in ISO 8601, which is commonly known as the
European week numbering system.
Syntax WEEKNUM(serial_number,[return_type])
Return_type Week begins on System
...
21 Monday 2
Given this,
=WEEKNUM("26/01/2017",21)
Will calculate as defined in ISO 8601 since Return_type 21 is the only one with System 2.
ISOWEEKNUM
=ISOWEEKNUM("26/01/2017")
Will also do it.

Related

Calculate month or quarter of a given date for ISOWEEK calendar

In Excel there is a ISOWEEK() function that returns the WEEK of a given date (according to the ISOWEEK system). I wonder how to create similar functions for the MONTH and for the QUARTER (i.e. given a certain data, what is its ISO month or its ISO quarter)? Thanks.
I have tried myself to build the functions but by looking at historical data I cant see a regular pattern, for instance depending on the year, some months have 4 or 5 weeks, but this change seems not following a regular pattern. Also the duration of the quarter for the ISOWEEK system is not so clear to me, shall I assume that the quarter is always 13 full weeks in the case of years with 52 weeks, and with 13+13+13+14 weeks when the year has 53 weeks?.
There are some functions to calculate the quarter as described here: https://www.extendoffice.com/documents/excel/2475-excel-convert-date-to-fiscal-year-or-quarter-or-month.html, for instance
Quarter for a given date:
=CHOOSE(MONTH(A6),3,3,3,4,4,4,1,1,1,2,2,2)
Fiscal month for a given date:
=CHOOSE(MONTH(A6),7,8,9,10,11,12,1,2,3,4,5,6)
However, seems that they don't completely match the ISOWEEK system (for more info about ISOWEEK: https://en.wikipedia.org/wiki/ISO_week_date ).
ISOMONTH should return the given month of a date, for instance ISOMONTH (15/01/2019) should return 1. In a similar way, ISOQUARTER (15/01/2019) should return 1.

Week number of a quarter

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 calculate DOT week numbers in Excel

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")

Excel weeknum function returns wrong week

Question is as in title.
I have a cell, "D4", with the date "09/07/2016" in it. Adjacent cell has formula "=weeknum(D4,1)". The output of this function is "28". But on a Sunday-Saturday basis, Saturday the 9th of July wasn't in week 28 - it was in week 27.
I thought this might be something to do with Saturday/Sunday and when the week starts and finishes, etc, so I tried multiple different dates from last week - Monday the 4th, Tuesday the 5th, Wednesday the 6th, etc. In each case, "weeknum" returns a value of "28".
I only noticed the problem because I have a macro which uses the value of the cell with the week number to look for a spreadsheet saved by our accounts team on a weekly basis. As they have - correctly - saved the spreadsheet as "week 27", it didn't work. I initially assumed that the accounts team were wrong, but I checked online and they are correct.
How could this happen? Surely Excel can't be wrong and I must have made a mistake of some sort?
I know that there is an issue with Excel not following ISO standards for when weeks 53 and 1 begin and end, but I don't see how that could affect a mid-year week.
It did occur to me that the issue might be to do with UK versus US date formatting. But, of course, the 7th of June wasn't in week 28 either.
That all is documented in WEEKNUM.
There are two systems used for this function:
System 1 The week containing January 1 is the first week of the
year, and is numbered week 1.
System 2 The week containing the first Thursday of the year is the
first week of the year, and is numbered as week 1. This system is the
methodology specified in ISO 8601, which is commonly known as the
European week numbering system.
Syntax
WEEKNUM(serial_number,[return_type])
Return_type Week begins on System
...
21 Monday 2
So =WEEKNUM("09/07/2016",21) will calculate as defined in ISO 8601 since Return_type 21 is the only one with System 2.
ISOWEEKNUM
=ISOWEEKNUM("09/07/2016")
will also do it.
=ISOWEEKNUM(a2)-1 returns the correct week for me, the same as =WEEKNUM(a2,21)-1

Find number of Each Day Type Left in Month (Excel)

Trying to find the number of weekdays LEFT in the month: e.g. 2 Mondays, 2 Tuesdays, etc in excel. Anyone know how I can go about doing this?
Thanks!
Which version of Excel are you using? If you have Excel 2010 you can customise NETWORKDAYS.INTL function to count any single day, e.g. to count Mondays from today until the end of the month (including today) you can use this formula
=NETWORKDAYS.INTL(TODAY(),EOMONTH(TODAY(),0),"0111111")
For Tuesdays use "1011111" for Wednesdays "1101111", etc.
There are specific codes for common "weekends", e.g. 11 for Sunday weekends, but, in fact, you can use any combination of days by using a string as shown - zeroes denote days to be counted, 1s are days to be ignored - the string starts with Monday and ends with Sunday

Resources