Search code examples
arraysgoogle-sheetsimportgoogle-sheets-formulagoogle-query-language

Stack multiple columns on top of eachother on Google Sheet?


I am using Google SpreadSheet, and I'm trying to import data from different sources together using a combination of query, importrange and curly brackets:

={Query(Importrange(SheetA),"select Col1,Col2,Col3,Col4 where Col1 is not null");
Query(Importrange(SheetB),"select Col1,Col2,Col3,Col4 where Col1 is not null")}

However, the resulting formula only returns SheetA data.

Since I only need 4 particular columns from SheetA and SheetB, I'd want the columns from both sheets to stack on top of each other like this:

Col1 Col2 Col3 Col4
Data SheetA Data SheetA Data SheetA Data SheetA
Data SheetB Data SheetB Data SheetB Data SheetB

I tried running each =query(importrange) individually and combining them afterward using {A:D;E:H} but it gives Result was not automatically expanded, please insert more rows error.

I tried looking for other similar threads but they were mostly about stacking different columns into one singular column. Can you help me with my case?


Solution

  • first, you need to run every importrange separately as standalone formula to connect your sheets by allowing access

    when done, only then, you can run this array:

    =QUERY({IMPORTRANGE("url_or_id", "SheetA!A:D"); 
            IMPORTRANGE("url_or_id", "SheetB!A:D")}, 
     "where Col1 is not null", 0)