How to calculate DOT week numbers in Excel - 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")

Related

FIRST FRIDAY OF THE YEAR

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.

how to calculate time difference in excel working hours only

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)

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.

Excel weeknum function showing wrong week number?

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.

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

Resources