简体   繁体   English

计算从每年二月的第一个星期日开始的一年中的第一周

[英]Calculate the first week of year which starts from first Sunday of every Feb

I have an issue here.我这里有问题。 I want to calculate the week nummber of first sunday of business year.我想计算营业年度第一个星期日的周数。 Where I work their calendar starts on February 1st.我工作的地方他们的日历从 2 月 1 日开始。 To calculate i have a column A2 in excel which has the date in mm/dd/yyyy format.为了计算我在excel中有一个A2列,它的日期是mm/dd/yyyy格式。 I want to generate the corresponding fiscal week for the column.我想为该列生成相应的会计周。

example of my result set:我的结果集示例:

for 2/1/15 the week of year number should be 1 For 2/7/16 the week number of year should be 1对于 2/1/15,周数应为 1 对于 2/7/16,周数应为 1

I tried the below formula, but its starting the week from the first day of the fiscal year and not the first sunday of the year.我尝试了下面的公式,但它从财政年度的第一天而不是一年的第一个星期日开始。

=INT((A1-WEEKDAY(E9165)-DATE(YEAR(A1+7-WEEKDAY(A1))-(MONTH(A1)<2),2,1))/7)+2

Please help...请帮助...

-Sandra -桑德拉

Assuming that your work years always start on the first sunday after February 1st:假设您的工作年份总是从 2 月 1 日之后的第一个星期日开始:

=IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))

We first determine the week number of the date starting from the first Sunday of February.我们首先确定从二月的第一个星期日开始的日期的周数。 To do this I have used WEEKNUM()-WEEKNUM(02/01/SAMEYEAR) taking 1 day from the date to force week 1 as Excel begins counting from week 0 by default.为此,我使用了WEEKNUM()-WEEKNUM(02/01/SAMEYEAR)从日期算起 1 天以强制第 1 周,因为 Excel 默认从第 0 周开始计数。 Using IF() we state that if the outcome is 0 or less then add the result to 52, which will give us the correct result for dates in January as they produce negative values.使用IF()我们声明,如果结果为 0 或更少,则将结果添加到 52,这将为我们提供 1 月份日期的正确结果,因为它们会产生负值。

Edit - Very long formula but gives you the week of the quarter in Q1 W1 format:编辑 - 很长的公式,但以 Q1 W1 格式为您提供本季度的一周:

=SUBSTITUTE(CONCATENATE("Q",INT(IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))/13)+(IF(INT(IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))-INT((IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))/13))*13)=0,0,1))," W",INT(IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))-INT((IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))/13))*13)),"W0","W1")

Apologies for the length, I tried multiple methods to try to find a neater solution, but this was all that I could get to work.很抱歉,我尝试了多种方法来尝试找到更简洁的解决方案,但这就是我能开始工作的全部。 It would be a lot neater if there were multiple columns used.如果使用多个列会更整洁。

使用这个公式:

=IF(A1>=IF(WEEKDAY(DATE(YEAR(A1),2,1),1)=1,DATE(YEAR(A1),2,1),DATE(YEAR(A1),2,7-WEEKDAY(DATE(YEAR(A1),2,1),1)+2)),ROUNDUP((A1-IF(WEEKDAY(DATE(YEAR(A1),2,1),1)=1,DATE(YEAR(A1),2,1),DATE(YEAR(A1),2,7-WEEKDAY(DATE(YEAR(A1),2,1),1)+2))+1)/7,0),ROUNDUP((A1-IF(WEEKDAY(DATE(YEAR(A1),2,1),1)=1,DATE(YEAR(A1)-1,2,1),DATE(YEAR(A1)-1,2,7-WEEKDAY(DATE(YEAR(A1)-1,2,1),1)+2))+1)/7,0))

Way late to the party but was looking for the answer and found this thread.聚会迟到了,但正在寻找答案并找到了这个线程。 Ended up play around with the function myself and it's much easier to just deduct the dates;最终自己玩弄了这个函数,只需扣除日期就容易多了; =WEEKNUM("date"- days you wish to offset) =WEEKNUM("date"- 您希望抵消的天数)

Ex;例如; If cell A1 holds my date, 2/1/2021 I wish to convert;如果单元格 A1 包含我的日期,则 2/1/2021 我希望转换; =WEEKNUM(A1-31) result "1". =WEEKNUM(A1-31) 结果“1”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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