3

Trying to understand if it is possible to apply ARRAYFORMULA to situations when QUERY is used in Google Sheets.

For example, I used QUERY for querying and aggregating a set of items, like so:

=QUERY($H$2:$I$17,"select sum(I) where H='"&A2&"' label sum(I) ''",0)

But in order to make that work across the spreadsheet, I will have to drag this formula down. There is also the ARRAYFORMULA thing, which is supposed to help with getting rid of excessive dragging, however it does not seem to work with QUERY, or am I just missing something?

A picture for a quick look:

query and arrayformula

And a shared file for the longer thinking:

https://docs.google.com/spreadsheets/d/1xOdqeESrFbrBknNYahSeF0ripA5fr2vVFQ-r--lkdA0/edit?usp=sharing

1

2 Answers 2

3

use this formula:

=QUERY(H2:I17, "select H,sum(I) where H is not null group by H label sum(I)''", 0)

and then you can do simple VLOOKUP like:

=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, QUERY(H2:I17, 
 "select H,sum(I) where H is not null group by H label sum(I)''", 0), 2, 0)))

0

Sign up to request clarification or add additional context in comments.

Comments

1

Here two method alternatively:

first ==>

=arrayformula(sumif(H2:H,"=" & unique(filter(H2:H,H2:H<>"")),I2:I))

second ==>

=arrayformula(
   query(
     filter({vlookup(H2:H,{A2:A,row(A2:A)},2,false),H2:I},H2:H<>"")
     ,"Select sum(Col3) group by Col1 label Sum(Col3) ''"
    )
  )

1 Comment

Thank you for this. Actually accepted your answer for 2 methods although another answer had some visuals.

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.