Home > Net >  If statements within a Query
If statements within a Query

Time:05-08

I'm using a query & importrange combo like this:

=IFERROR(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1EizWsVwZfUy1NDRwmmWEpj2OxTGvBjP9-YBbds9xmr0/edit#gid=0", "'Locations'!A2:C"), "select Col3 where Col1='"&J4&"' and Col1<>''"))

But Instead of just searching column 1 and returning the associated value in column 3, I would like it to return the associated value in:
Col3 if the value is in Col1
Col7 if the value is in Col5
Col11 if the value is in Col9

It can throw an error if the value is in more than one place, or return the result at the first occurrence, either way is fine.

I'm trying to do this using "countif" within the query but am not having a much luck.

CodePudding user response:

try:

=IFERROR(QUERY({
 IMPORTRANGE("1EizWsVwZfUy1NDRwmmWEpj2OxTGvBjP9-YBbds9xmr0", "Locations!A2:C");
 IMPORTRANGE("1EizWsVwZfUy1NDRwmmWEpj2OxTGvBjP9-YBbds9xmr0", "Locations!E2:G");
 IMPORTRANGE("1EizWsVwZfUy1NDRwmmWEpj2OxTGvBjP9-YBbds9xmr0", "Locations!I2:K")}, 
 "select Col3 where Col1='"&J4&"' and Col1 is not null", ))
  • Related