简体   繁体   中英

WEEKNUM across multiple years

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM