4/24/2025

how to use query function with importrange in google sheets

IN SUMMARY

The IMPORTRANGE function in Google Sheets allows you to import data from other spreadsheets, while the QUERY function can be used to filter and manipulate the imported data. Combining these two functions enables you to import and process data from external sources efficiently.

Using IMPORTRANGE

The IMPORTRANGE function takes two arguments: the URL of the spreadsheet you want to import data from, and the range of cells you want to import. For example: `=IMPORTRANGE("https://docs.google.com/spreadsheets/d/abc123/edit", "Sheet1!A1:D10")`

To import data from a shared spreadsheet, you need to grant access to the spreadsheet you're importing from. When you first use IMPORTRANGE, you'll be prompted to allow access. Click 'Allow access' to proceed.

Instead of specifying a fixed range, you can use a cell reference to make the range dynamic. This allows you to easily switch between different sheets or ranges by changing the cell value. For example: `=IMPORTRANGE("https://docs.google.com/spreadsheets/d/abc123/edit", A1)`

Combining IMPORTRANGE with QUERY

The QUERY function can be used to filter and manipulate the data imported using IMPORTRANGE. For example, to remove empty rows: `=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/abc123/edit", "Sheet1!A1:D"), "SELECT * WHERE Col1 IS NOT NULL")`

You can append data from multiple ranges using IMPORTRANGE and QUERY. Separate the IMPORTRANGE calls with a semicolon, and wrap the entire formula in curly braces: `{=QUERY(IMPORTRANGE("url1", "range1"); IMPORTRANGE("url2", "range2"), "SELECT * WHERE Col1 IS NOT NULL")}`

When using QUERY with IMPORTRANGE, you need to reference columns using the `Col` syntax (e.g., `Col1`, `Col2`) instead of column letters (e.g., `A`, `B`). This is because the QUERY function doesn't recognize column letters when working with external data.

Advanced Usage

By combining IMPORTRANGE and QUERY, you can import and combine data from multiple spreadsheets into a single sheet. This can be useful for consolidating data from various sources or creating reports.

You can automate the import and processing of data by setting up a script or trigger to run the IMPORTRANGE and QUERY functions at regular intervals. This can save time and ensure that your data is always up-to-date.

The output of IMPORTRANGE and QUERY can be used as input for other functions, such as VLOOKUP, SUMIF, or custom functions. This allows you to perform complex data analysis and calculations on imported data.

Want to automate your busy work in Google Sheets with AI?

Videos