Search code examples
google-sheetsarray-formulasgoogle-sheets-query

Fill Google Sheets QUERY down column


How can I fill this QUERY down a column without dragging?

=SUM(
  QUERY(
   {
    'Report: Materials List'!B9:B,
    'Report: Materials List'!C9:C,
    'Report: Materials List'!D9:D,
    'Report: Materials List'!E9:E,
    'Report: Materials List'!F9:F,
    'Report: Materials List'!G9:G,
    'Report: Materials List'!H9:H,
    'Report: Materials List'!I9:I
   },
  "SELECT Col4*Col6 WHERE Col1 = '"&A3&"' AND Col2 = '"&B3&"' AND Col1 IS NOT NULL LABEL Col4*Col6 '' format Col4*Col6 '$#'",0
 )
)

The QUERY is in J3 and I would like for it to apply to J3:J considering unique values in A3:A and B3:B.

My sample sheet


Solution

  • You can get all, with this single formula

    =ArrayFormula(query({'Report: Materials List'!B9:C, 'Report: Materials List'!E9:E * 'Report: Materials List'!G9:G}, "Select Col1, Col2, sum(Col3) where Col1 <>'' group by Col1, Col2 label sum(Col3) '' format sum(Col3) '$00'"))
    

    (see cell N3).

    If you only want to return the second column, you can add a vlookup to match the values in columns A and B.

    =ArrayFormula(if(len(A3:A&B3:B), vlookup(A3:A&B3:B, query({'Report: Materials List'!B9:B&'Report: Materials List'!C9:C, 'Report: Materials List'!E9:E * 'Report: Materials List'!G9:G},"Select Col1, sum(Col2) where Col1 <>'' group by Col1 label sum(Col2) ''"), 2, 0),))