0
votes

I have an order sheet in which Column K has delivery date, column I has the qty. I want a weekly order summary.

I used the below in column J

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

=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.

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.

The starting date of the week is also wrong for the dates belonging to year 2020 (due to 2019 fed in M1).

I tried combining year and week in column J by array formula

=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.

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.

=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

The report is in Daily_Plan sheet in K1

1

1 Answers

0
votes

I solved it by the below formula :

In the data sheet in the column next to date, I made the below formula in M1

=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

Then I made a pivot report based on Column 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

Pl. note 53 rd week of 2019 and first week of 2020 actually fall in the same 7 days. 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)

for weeks falling in 2019

and

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

for weeks falling in 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

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.

Note how the 53 rd week or 2019 and first week of 2020 are both starting on 30-Dec. Actually it must be summed.

But, it works!!