-1

I am trying to run a some nested IF statements with a query (with an import range to another sheet). Such that, if cell B2 is 'ABC', it will query the ABC sheet and return the value of a cell on that sheet. Same for the other two sheets, 'XYZ' and '123', all as one long formula. Here's what I have thus far, any help would be appreciated, thank you!

=IF(B2 = "ABC", (query({IMPORTRANGE("[ABC URL HERE]", "This Sheet!A2:H")}, "Select Col9 where Col5 = '"&$D2&"' LIMIT 1",0,IF(B2 = "XYZ", (query({IMPORTRANGE("[XYZ URL HERE]", "That Sheet Sheet!A2:H")}, "Select Col9 where Col5 = '"&$D2&"' LIMIT 1",0,)IF(B2 = "123", (query({IMPORTRANGE("[123 URL HERE]", "Their Sheet Sheet!A2:H")}, "Select Col9 where Col5 = '"&$D2&"' LIMIT 1",0,)))))

Jerome

player0
  • 124,011
  • 12
  • 67
  • 124
Jump_Ace
  • 193
  • 1
  • 3
  • 11
  • 3
    Please provide your data sample as well as the desired outcome. – Osm Nov 03 '22 at 02:53
  • PSA: Do NOT share [spreadsheets](//meta.stackoverflow.com/a/260455)/[images](//meta.stackoverflow.com/q/285551) as the only source of data, to avoid closure of the question. Make sure to add input and expected output as **plain text table** to the question. [Click here](//webapps.stackexchange.com/a/161855) to create a table easily, which are **easier to copy/paste as well**. Also, note that [your email address can also be accessed by the public](//meta.stackoverflow.com/q/394304), if you share Google files. – TheMaster Nov 03 '22 at 19:25

1 Answers1

2

try:

=IF(B2 = "ABC", QUERY({IMPORTRANGE("[ABC URL HERE]", "This Sheet!A2:H")}, 
 "select Col9 where Col5 = '"&$D2&"' limit 1", 0),
 IF(B2 = "XYZ", QUERY({IMPORTRANGE("[XYZ URL HERE]", "That Sheet Sheet!A2:H")}, 
 "select Col9 where Col5 = '"&$D2&"' limit 1", 0),
 IF(B2 = "123", QUERY({IMPORTRANGE("[123 URL HERE]", "Their Sheet Sheet!A2:H")}, 
 "select Col9 where Col5 = '"&$D2&"' limit 1", 0), )))
player0
  • 124,011
  • 12
  • 67
  • 124