0

Tried several times with Query formula, but failed so far.

I have a simple source that looks like this, columns of date, product and quantity.

Log

On another sheet I have a table that has the products on the Y-axis and the years on the X-axis. Both axis I want to expand over time with the products and years available in the source and their respective sum of quantities in the grid.

Summary

Existing formulas are:

To put out the years in row 1.

=transpose(ArrayFormula(SORT(UNIQUE(YEAR(FILTER(Log!A2:A,ISNUMBER(Log!A2:A)))),0,false)))

To put out the products in column A.

=query(Products!A2:A,"select A where A is not null order by A")

What formula I have to put in B2 to find all the quantities from the source table matching their respective year of date and their product?

1 Answer 1

1

You may try:

=arrayformula(query({year(Log!A2:A),Log!C2:D},"Select Col2,sum(Col3) Where Col2<>'' group by Col2 pivot Col1")) 
  • Adjust the ranges in the formulas as per your sheet
Sign up to request clarification or add additional context in comments.

8 Comments

Works nicely out of the box already. 👍 Let's say I want to do the same for months instead of years. How do I put out all 12 months, not just the existing in Log!A2:A and how do I replace the resulting integer value with its month (January, February, ...)?
It would help if you could share a sample sheet with realistic-demo data and expected output(manually entered) so as for us to get a clear picture & workout a solution. You may also use the anonymous blank sheet maker provided by docs community forum incase you do not wish to share a sheet from your google account.
Sure @rockinfreakshow. Here's an example: docs.google.com/spreadsheets/d/…
There's no input data added within the sheet
Formula added to the test sheet
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.