0
votes

I am trying to calculate the week number of the fiscal year that a given date falls on - our fiscal year begins on July 1 and ends June 30, weeks go from Sun-Sat and the data contain multiple years.

For example: 7/1/2017 falls on a Saturday, so it would be week 1 in the fiscal year. 7/2-7/8, 2017 would be week 2 and the week of 6/23-6/30, 2018 would be week 52, this would start over to week 1 on 7/1/2018.

Any help would be appreciated, thank you!

Screenshot of data I'm working with

Screenshot of formulas in Weekday, FiscalYear, and FiscalQuarter]

3
If July 1st falls on a Sunday, is it day #1 of week #1 of the following year? Or is the following Sunday day #1 ??Gary's Student
clearly if we can determine day#1/week#1 we can calculate the difference from a given date mod 7 (nicht wahr?)Gary's Student
I would love it if you used ISO 8601 date formats (i.e. yyyy/MM/dd). Less than 5% of the world uses the M/d/yyyy format.Enigmativity

3 Answers

1
votes

Unlike the others, I understand you to mean that the fiscal year always starts on July 1, and that the week changes on Sunday.

Algorithm

  • Compute preceding July 1: =DATE(YEAR(A2)-IF(MONTH(A2)>=7,0,1),7,1)
  • Compute first Sunday of the fiscal year: =prevJul1 +7-WEEKDAY(prevJul1 +6)
  • Compute weeknumber since first Sunday: =INT((A2-firstSunday)/7)+1
  • Add 1 if prevJul1 is not a Sunday

Putting it all together:

=INT((A2-(DATE(YEAR(A2)-IF(MONTH(A2)>=7,0,1),7,1)+7-WEEKDAY(DATE(YEAR(A2)-IF(MONTH(A2)>=7,0,1),7,1)+6)))/7)+1+(WEEKDAY(DATE(YEAR(A2)-IF(MONTH(A2)>=7,0,1),7,1))<>1)

enter image description here

0
votes

If A1 contains July 1st of any year, then B1:

=A1+CHOOSE(WEEKDAY(A1),0,6,5,4,3,2,1)

will give the date of the first Sunday after or on that date. This is day #1 of week #1 of the new fiscal year

Now it is easy to get the week number:

=INT(1+(date_in_question - day#1week#1)/7)

Copy B1 and PasteSpecialValues and formats into C1

C1 is the starting date of the new fiscal year

In D1 put an arbitrary date within the new fiscal year. In E1 enter:

=INT(1+(D1-C1)/7)

enter image description here

0
votes

Computes the week number for any date where week 1 starts on the first Sunday on or after the 1st of July:

=INT(([@Date]-(DATE(YEAR([@Date]-WEEKDAY([@Date])+1)-IF(MONTH([@Date]-WEEKDAY([@Date])+1)>=7,0,1),7,1)+MOD(8-WEEKDAY(DATE(YEAR([@Date]-WEEKDAY([@Date])+1)-IF(MONTH([@Date]-WEEKDAY([@Date])+1)>=7,0,1),7,1)),7)))/7)+1

Here's some sample output:

Date           | WeekNo
-------------- | ------
2017/06/17 Sat | 50    
2017/06/18 Sun | 51    
2017/06/19 Mon | 51    
2017/06/20 Tue | 51    
2017/06/21 Wed | 51    
2017/06/22 Thu | 51    
2017/06/23 Fri | 51    
2017/06/24 Sat | 51    
2017/06/25 Sun | 52    
2017/06/26 Mon | 52    
2017/06/27 Tue | 52    
2017/06/28 Wed | 52    
2017/06/29 Thu | 52    
2017/06/30 Fri | 52    
2017/07/01 Sat | 52    
2017/07/02 Sun | 1     
2017/07/03 Mon | 1     
2017/07/04 Tue | 1     
2017/07/05 Wed | 1     
2017/07/06 Thu | 1     
2017/07/07 Fri | 1     
2017/07/08 Sat | 1     
2017/07/09 Sun | 2     
2018/06/17 Sun | 51    
2018/06/18 Mon | 51    
2018/06/19 Tue | 51    
2018/06/20 Wed | 51    
2018/06/21 Thu | 51    
2018/06/22 Fri | 51    
2018/06/23 Sat | 51    
2018/06/24 Sun | 52    
2018/06/25 Mon | 52    
2018/06/26 Tue | 52    
2018/06/27 Wed | 52    
2018/06/28 Thu | 52    
2018/06/29 Fri | 52    
2018/06/30 Sat | 52    
2018/07/01 Sun | 1     
2018/07/02 Mon | 1     
2018/07/03 Tue | 1     
2018/07/04 Wed | 1     
2018/07/05 Thu | 1     
2018/07/06 Fri | 1     
2018/07/07 Sat | 1     
2018/07/08 Sun | 2     
2018/07/09 Mon | 2     
2019/06/17 Mon | 51    
2019/06/18 Tue | 51    
2019/06/19 Wed | 51    
2019/06/20 Thu | 51    
2019/06/21 Fri | 51    
2019/06/22 Sat | 51    
2019/06/23 Sun | 52    
2019/06/24 Mon | 52    
2019/06/25 Tue | 52    
2019/06/26 Wed | 52    
2019/06/27 Thu | 52    
2019/06/28 Fri | 52    
2019/06/29 Sat | 52    
2019/06/30 Sun | 53    
2019/07/01 Mon | 53    
2019/07/02 Tue | 53    
2019/07/03 Wed | 53    
2019/07/04 Thu | 53    
2019/07/05 Fri | 53    
2019/07/06 Sat | 53    
2019/07/07 Sun | 1     
2019/07/08 Mon | 1     
2019/07/09 Tue | 1     
2020/06/17 Wed | 50    
2020/06/18 Thu | 50    
2020/06/19 Fri | 50    
2020/06/20 Sat | 50    
2020/06/21 Sun | 51    
2020/06/22 Mon | 51    
2020/06/23 Tue | 51    
2020/06/24 Wed | 51    
2020/06/25 Thu | 51    
2020/06/26 Fri | 51    
2020/06/27 Sat | 51    
2020/06/28 Sun | 52    
2020/06/29 Mon | 52    
2020/06/30 Tue | 52    
2020/07/01 Wed | 52    
2020/07/02 Thu | 52    
2020/07/03 Fri | 52    
2020/07/04 Sat | 52    
2020/07/05 Sun | 1     
2020/07/06 Mon | 1     
2020/07/07 Tue | 1     
2020/07/08 Wed | 1     
2020/07/09 Thu | 1     
2021/06/17 Thu | 50    
2021/06/18 Fri | 50    
2021/06/19 Sat | 50    
2021/06/20 Sun | 51    
2021/06/21 Mon | 51    
2021/06/22 Tue | 51    
2021/06/23 Wed | 51    
2021/06/24 Thu | 51    
2021/06/25 Fri | 51    
2021/06/26 Sat | 51    
2021/06/27 Sun | 52    
2021/06/28 Mon | 52    
2021/06/29 Tue | 52    
2021/06/30 Wed | 52    
2021/07/01 Thu | 52    
2021/07/02 Fri | 52    
2021/07/03 Sat | 52    
2021/07/04 Sun | 1     
2021/07/05 Mon | 1     
2021/07/06 Tue | 1     
2021/07/07 Wed | 1     
2021/07/08 Thu | 1     
2021/07/09 Fri | 1     
2022/06/17 Fri | 50    
2022/06/18 Sat | 50    
2022/06/19 Sun | 51    
2022/06/20 Mon | 51    
2022/06/21 Tue | 51    
2022/06/22 Wed | 51    
2022/06/23 Thu | 51    
2022/06/24 Fri | 51    
2022/06/25 Sat | 51    
2022/06/26 Sun | 52    
2022/06/27 Mon | 52    
2022/06/28 Tue | 52    
2022/06/29 Wed | 52    
2022/06/30 Thu | 52    
2022/07/01 Fri | 52    
2022/07/02 Sat | 52    
2022/07/03 Sun | 1     
2022/07/04 Mon | 1     
2022/07/05 Tue | 1     
2022/07/06 Wed | 1     
2022/07/07 Thu | 1     
2022/07/08 Fri | 1     
2022/07/09 Sat | 1