How to Import Data with Conditions using Google Sheets IMPORTRANGE Function

Have you ever wondered if you could use conditions with the IMPORTRANGE function in Google Sheets? Well, you can! In this tutorial, I’ll show you how to leverage the power of the QUERY function to incorporate conditions into the IMPORTRANGE function. This nifty trick will help you become a proficient Google Sheets user in no time!

A Simple Example

To illustrate this concept, let’s consider two Google Sheets files: “TestA” and “TestB.” The former contains the data we want to import, while the latter is where we’ll be importing the data to.

TestA and TestB

Let’s say we want to import data from “TestA” to “TestB,” but only if the values in column A of “TestA” are equal to “Safety Helmet.” Initially, we can use the simple IMPORTRANGE function to import all the data from “TestA” to “TestB” without any conditions. Here’s the formula:

=IMPORTRANGE("HTTPS://DOCS.GOOGLE.COM/SPREADSHEETS/D/1W1UNLCVHSPD2DHPKTF7MDQ0MI3VRVM40KR-9HFSJPIW/EDIT#GID=1641552592","SHEET1OFTESTA!A1:G9")

However, to add conditions, we need to combine the QUERY function with the IMPORTRANGE function.

Combining QUERY and IMPORTRANGE Functions

Before we proceed, let me show you how to use the QUERY function independently to filter data. The following formula will only display rows where column A is equal to “Safety Helmet”:

=QUERY(A1:G9,"where A='Safety Helmet'")

Now, let’s combine the two formulas. First, replace the highlighted part of the QUERY formula with the IMPORTRANGE formula and wrap it with curly brackets. Additionally, replace the column identifier “A” with “Col1” in the QUERY formula. Here’s the resulting formula:

=QUERY({IMPORTRANGE("HTTPS://DOCS.GOOGLE.COM/SPREADSHEETS/D/1W1UNLCVHSPD2DHPKTF7MDQ0MI3VRVM40KR-9HFSJPIW/EDIT#GID=1641552592","SHEET1OFTESTA!A1:G9")},"where Col1='Safety Helmet'")

By using this combined formula, you can import data from “TestA” to “TestB” only if the values in column A of “TestA” match the condition.

Conclusion

Congratulations! You now know how to use the IMPORTRANGE function with conditions in Google Sheets. You can even apply multiple filters by leveraging the power of the QUERY function. If you need more QUERY formulas, you can find plenty of them on Crawlan.com. Keep exploring and becoming a Google Sheets pro!

And if you’re up against the roadblock of date filtering, don’t worry! Check out the examples of Query formula Date Criteria on Crawlan.com for some inspiration:

  1. How to Use Date Criteria in Query Function in Google Sheets.
  2. Convert Date to String Using the Long-winded Approach in Google Sheets.
  3. Examples of the Use of Literals in Query in Google Sheets.
  4. Simple Comparison Operators in Sheets Query.
  5. How to Sum, Avg, Count, Max, and Min in Google Sheets Query.
  6. How to Use Arithmetic Operators in Query in Google Sheets.

Happy Sheets-ing!

Related posts