6.2 C
London
Thursday, December 19, 2024
HomeSoftware TutorialsGoogle SheetsGoogle Sheets: How to Query From Another Sheet

Google Sheets: How to Query From Another Sheet

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

To query from another tab within the same spreadsheet in Google Sheets, you can use the following syntax:

=query(stats!A1:C9, “select A, B“, 1)

This returns columns A and B from the cell range A1:C9 within the tab named stats. The 1 specifies that there is 1 header row at the top of the dataset being queried.

To query from another spreadsheet entirely, you can use the following syntax:

=query(importrange(“URL“,  “stats!A1:C9“), “select Col1, Col2“, 1)

This returns the first two columns from the cell range A1:C9 within the tab named stats within the Google Sheets spreadsheet with a specific URL.

The following examples show how to use these functions in practice.

Example: Query from Tab in Same Spreadsheet

Suppose we have the following Google Sheets spreadsheet with two tabs: 

  • stats
  • new_sheet

To perform a query on the data in the stats tab and return the results of the query in the new_sheet tab, we can type the following formula in cell A1 of the new_sheet tab:

Example: Query from Another Spreadsheet

Now suppose that we would like to query from another spreadsheet entirely. To do so, we simply need to identify the URL of the Google Sheets spreadsheet that we’d like to query from.

For example, suppose the data we’re interested in is located at the following URL:

We can use the importrange() function to query data from this spreadsheet:

Notice the subtle difference between this example and the previous example:

  • When querying from a tab within the same spreadsheet, we use select A, B
  • When querying from an entirely different spreadsheet, we use select Col1, Col2

You can find more Google Sheets tutorials on this page.

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories