Home > other >  Google Sheets Query With Multiple IF Statements
Google Sheets Query With Multiple IF Statements

Time:11-04

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

CodePudding user response:

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), )))
  • Related