简体   繁体   English

如何在谷歌表的arrayformula中加入year和weeknum

[英]how to join year and weeknum in arrayformula in google sheet

I have an order sheet in which Column K has delivery date, column I has the qty.我有一个订单,其中 K 列有交货日期,I 列有数量。 I want a weekly order summary.我想要每周订单摘要。

I used the below in column J我在 J 列中使用了以下内容

=ArrayFormula( IF(ROW(A:A)=1, "Week", IF(not(isblank((I:I))), weeknum(K:K),""))) =ArrayFormula( IF(ROW(A:A)=1, "Week", IF(not(isblank((I:I))), weeknum(K:K),"")))

In the pivot report sheet I use the below formula (in M2:M) to show the starting date of the week (with "2019" fed in M1)在数据透视报告表中,我使用以下公式(在 M2:M 中)显示一周的开始日期(在 M1 中输入“2019”)

=DATE($M$1, 1, -3 + 7 * K2 - WEEKDAY(DATE($M$1, 1, 4), 2) + 1) =DATE($M$1, 1, -3 + 7 * K2 - WEEKDAY(DATE($M$1, 1, 4), 2) + 1)

This worked well as long as the dates are within year 2019.只要日期在 2019 年之内,这种方法就很有效。

But, now some orders of 2020 have come in and the weeknum has become 1 - this creates problems while sorting in pivot table and there is weeknum 53 and the December last week and Jan first week are shown as two different weeks.但是,现在 2020 年的一些订单已经进来,并且周数变为 1 - 这在数据透视表中排序时会产生问题,并且周数为 53,上周 12 月和 1 月第一周显示为两个不同的周。

The starting date of the week is also wrong for the dates belonging to year 2020 (due to 2019 fed in M1).对于属于 2020 年的日期(由于 2019 年在 M1 中输入),一周的开始日期也是错误的。

I tried combining year and week in column J by array formula我尝试通过数组公式在 J 列中组合年份和周

=ArrayFormula( IF(ROW(A:A)=1, "Week", IF(not(isblank((I:I))), 52*year(K:K)+weeknum(K:K),""))) =ArrayFormula( IF(ROW(A:A)=1, "Week", IF(not(isblank((I:I))), 52*year(K:K)+weeknum(K:K),"" )))

This solved part of the problem in pivot table (the last week problem disappeared) but, how to get the first date of the week near the week number?这解决了数据透视表中的部分问题(上周问题消失了)但是,如何在周数附近获得一周的第一个日期?

Or suggest another way to get weekly summary and print the first day of the week (Monday) near the weeknum in the pivot table.或者建议另一种方法来获取每周摘要并在数据透视表中的 weeknum 附近打印一周的第一天(星期一)。

The below query solved the problem partially.下面的查询部分解决了这个问题。 It is able to sort correctly.它能够正确排序。 But, the 53 rd week and 1 st week are still seperate and i am not able to display the first day of the week.但是,第 53 周和第 1 周仍然是分开的,我无法显示一周的第一天。

=ARRAYFORMULA( QUERY({ YEAR(Plan!K2:K)&" "&WEEKNUM(Plan!K2:K), Plan!I2:I, YEAR(Plan!K2:K)+WEEKNUM(Plan!K2:K)*0.01923076923}, "select Col1,sum(Col2),Col3 where Col2 is not null group by Col1,Col3 order by Col1 label sum(Col2)''", 0)) =ARRAYFORMULA(QUERY({ YEAR(Plan!K2:K)&" "&WEEKNUM(Plan!K2:K), Plan!I2:I, YEAR(Plan!K2:K)+WEEKNUM(Plan!K2:K)* 0.01923076923}, "select Col1,sum(Col2),Col3 where Col2 is not null group by Col1,Col3 order by Col1 label sum(Col2)''", 0))

Example sheet示例表

https://docs.google.com/spreadsheets/d/1FT1pk3BrQ_VBLpJWif9A5z0LFIB4pZugh0kLM-QtL_s/edit?usp=sharing https://docs.google.com/spreadsheets/d/1FT1pk3BrQ_VBLpJWif9A5z0LFIB4pZugh0kLM-QtL_s/edit?usp=sharing

The report is in Daily_Plan sheet in K1该报告位于 K1 的 Daily_Plan 表中

I solved it by the below formula :我用下面的公式解决了它:

In the data sheet in the column next to date, I made the below formula in M1在日期旁边列的数据表中,我在 M1 中制作了以下公式

=ArrayFormula( IF(ROW(A:A)=1, "Week", IF(not(isblank((I:I))), text((K:K),"yy")&"-"&text(weeknum(K:K),"00"),""))) =ArrayFormula( IF(ROW(A:A)=1, "Week", IF(not(isblank((I:I))), text((K:K),"yy")&"-"&text( weeknum(K:K),"00"),"")))

It gave me a column as below它给了我一个专栏,如下所示

QC_Dt QC_dn Week Month 13-07-19 43659 19-28 19-07 15-07-19 43661 19-29 19-07 17-08-19 43694 19-33 19-08 20-08-19 43697 19-34 19-08 22-08-19 43699 19-34 19-08 23-08-19 43700 19-34 19-08 24-08-19 43701 19-34 19-08 QC_Dt QC_dn 周 月 13-07-19 43659 19-28 19-07 15-07-19 43661 19-29 19-07 17-08-19 43694 19-33 19-08 20-4938 -08 22-08-19 43699 19-34 19-08 23-08-19 43700 19-34 19-08 24-08-19 43701 19-34 19-08

Then I made a pivot report based on Column M然后我根据列 M 做了一个数据透视报告

Week SUM of Lot_Qty 19-34 4 19-35 3 19-36 2 19-37 6 19-38 8 19-39 6 19-40 7 19-41 3 19-42 100 19-43 136 19-44 1 19-45 6 19-46 16 19-47 36 19-48 30 19-50 2 19-51 20 19-52 32 19-53 76 20-01 60 20-02 101 20-03 94 20-04 8 20-05 36 Lot_Qty 的周总和 19-34 4 19-35 3 19-36 2 19-37 6 19-38 8 19-39 6 19-40 7 19-41 3 19-42 100 19-43 446 - 19- 45 6 19-46 16 19-47 36 19-48 30 19-50 2 19-51 20 19-52 32 19-53 76 20-01 60 20-02 101 20-03 90-64 82

Pl. Pl。 note 53 rd week of 2019 and first week of 2020 actually fall in the same 7 days.注意 2019 年的第 53 周和 2020 年的第一周实际上是在同一 7 天。 But, it appears as two weeks.但是,它显示为两周。 Not yet able to solve this yet.目前还不能解决这个问题。

Then I fed the below formula next to the pivot report然后我在数据透视报告旁边输入了以下公式

=date(value("20"+left(K2,2)),1,1) + (7*(right(K2,2)-1) - 1) =date(value("20"+left(K2,2)),1,1) + (7*(right(K2,2)-1) - 1)

for weeks falling in 2019 2019 年下降的几周

and

=date(value("20"+left(K2,2)),1,1) + (7*(right(K2,2)-1) - 2) =date(value("20"+left(K2,2)),1,1) + (7*(right(K2,2)-1) - 2)

for weeks falling in 2020. 2020 年下降的几周。

I got我有

Week SUM of Lot_Qty Week Start 19-34 4 19-Aug 19-35 3 26-Aug 19-36 2 2-Sep 19-37 6 9-Sep 19-38 8 16-Sep 19-39 6 23-Sep 19-40 7 30-Sep 19-41 3 7-Oct 19-42 100 14-Oct 19-43 136 21-Oct 19-44 1 28-Oct 19-45 6 4-Nov 19-46 16 11-Nov 19-47 36 18-Nov 19-48 30 25-Nov 19-50 2 9-Dec 19-51 20 16-Dec 19-52 32 23-Dec 19-53 76 30-Dec 20-01 60 30-Dec 20-02 101 6-Jan 20-03 94 13-Jan 20-04 8 20-Jan 20-05 36 27-Jan 20-06 6 3-Feb 20-07 6 10-Feb 20-08 6 17-Feb Lot_Qty 的周 SUM 周开始 19-34 4 19-Aug 19-35 3 26-Aug 19-36 2 2-Sep 19-37 6 9-Sep 19-38 8 16-Sep 19-39 6 23-Sep 19- 40 7 30-Sep 19-41 3 7-Oct 19-42 100 14-Oct 19-43 136 21-Oct 19-44 1 28-Oct 19-45 6 4-Nov 19-46 16 19-43-Nov 36 18-Nov 19-48 30 25-Nov 19-50 2 9-Dec 19-51 20 16-Dec 19-52 32 23-Dec 19-53 76 30-Dec 20-01 60 30-12-20 6-Jan 20-03 94 13-Jan 20-04 8 20-Jan 20-05 36 27-Jan 20-06 6 3-Feb 20-07 6 10-Feb 20-08 6 17-Feb

It is not very elegant.它不是很优雅。 I have to copy the formula to new rows and I have to slightly modify the formula for 2019 or 2020 manually.我必须将公式复制到新行,并且必须手动稍微修改 2019 或 2020 的公式。

Note how the 53 rd week or 2019 and first week of 2020 are both starting on 30-Dec.请注意第 53 周或 2019 年和 2020 年的第一周是如何从 12 月 30 日开始的。 Actually it must be summed.其实应该总结一下。

But, it works!!但是,它有效!!

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

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