WEEKNUM across multiple years - excel

I am doing a cohort analysis for a subscription service from September 2021 - January 2023 and using the WEEKNUM formula, but of course each year starts on a different day and I am struggling to figure out how to mitigate this for all dates on the worksheet. Additionally, I just want there to be 52 weeks each year (not 53, week 52/1 can overlap years).
Presumably it will need to be some sort of IF statement but I just can't seem to visualise it!
I have tried =WEEKNUM(D2,15), which is fine for days in 2021 as it starting on a Friday, but not for days in 2022 and 2023 when I drag the formula down all of the dates

I think I've figured out the answer!
=IFS(D2<>"2023",(WEEKNUM(D2,1)),D2<>"2022",WEEKNUM(D2,16),D2<>"2021",WEEKNUM(D2,15))
I have tested it against some of the dates manually and it seems to hold true

Related

MS Excel how to proporationately spread $ values over years

Hi All and thank you in advance for any help.
I have several projects that start and finish in different years and want to spread the contract value proportionately over each year. For example a project might start on 1 July 2020 and end 30 June 2022 with a value of $20 million. So how would I automatically populate a value for each of these years, this example would have $5m in 2020, $10m in 2021 and $5m in 2022. The issue is I have about 100 projects that have started since 2013 and some are not due to finish until 2024 so some degree of auomation will help me. I have set up a spread sheet as follows
Excel spreadsheet
Hope this makes sense and any help will be much appreciated.
Good Day,
Try the following formula in the "Contract Days per Year":
=MAX(0,MIN(DATE(E$1,12,31),$B3)-MAX(DATE(E$1,1,1),$A3)+1)
Then you will just multiply the result in the "Contract Value by Year"
for 2019 year, copy the values under 2018 and paste it under 2019
hope it helped

Excel - count a specific value based on a part of another cell

I thought this would be a no brainer. But I really need help to solve it.
I have a row of dates: 10 july 2020, 11 july 2020 and so on (Swedish excel).
Below each date are strings for example "FP". I wish to achieve a counter for each "FP" that is below a specific month of a year, such as july 2020.
The way I approached this was with
=COUNTIFS(G1:UG1;"*july 2020";G2:UG2;"FP")
However the * doesn't do what I want it to. Is there another way to do this?
Please help! :)
The dates are true dates and as such the july 2020 is just a format of a number and not actually there.
Instead BookEnd the date:
=COUNTIFS(G1:UG1;">="&DATE(2020;7;1);G1:UG1;"<"&DATE(2020;8;1);G2:UG2;"FP")

Compare two week numbers from different years in Excel

I have some calculations that are strongly dependent on "this week", "next week", etc.
Let's say I have a date (Column A). I can use WEEKNUM((A1), 2) in Column B to get the week number.
In Column C, I can enter this formula to check if the event is this week or next week.
=IF(B1=WEEKNUM((TODAY()),2),"this week",IF(B1=WEEKNUM((TODAY()+7),2),"next week","way in the future"))
This all works great until I have events that cross into next year. So December 31, 2019, will be week 53 and December 31, 2020, will be week 53.
This is an issue because I need a way to account that December 31, 2020 happens later than December 31, 2019.
How do I account for change in years in this formula?
Update:
Adding YEAR as an additional condition will allow me to compare if the date HAS a different year but it still won't let me dynamically calculate, this week, next week.
In this second example, I set two dates and set my computer time as December 31 2019. The result is that instead of reporting 1/1/2020 as "next week" the formula returns "way in the future" which is incorrect.
Is there basically a way to subtract or add weeks using serial week number since epoch time?
Eh, I think I figured it out. Instead of comparing week numbers, we extract the Monday of each week and perform a similar comparison like before. Except we now have the entire date instead of just the week number.
=IF(A2-MOD(A2-2,7)=TODAY()-MOD(TODAY()-2,7),"this week",IF(A2-MOD(A2-2,7)=TODAY()-MOD(TODAY()-2,7)+7,"next week","way in the future"))

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)

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

Resources