Search code examples
google-sheetsgoogle-sheets-query

IF statement inside QUERY in Google Sheets


I have a google sheet where I have several projects listed. With a QUERY function I am retrieving information into another sheet for reporting purposes.

The formula I am using is: =QUERY($A$2:$D$8,"IF(OR($C2=1,$C2=2,$C2=3), Select A, B, D, Select A, B, C)",0)

What I am struggling to do is placing an IF statement inside the QUERY function.

I would like to get the Date 2 (Col4) value if the Status (Col2) value is "1", "2" or "3". Otherwise, if the Status (Col2) value is "4", "5" or "6" I would like the Query to return the Date 1 (Col3)

Any help would be appreiated. Thanks!

Screenshot


Solution

  • The formula would be like this:

    =ArrayFormula(query({A2:B8,if(B2:B8<=3,D2:D8,C2:C8)},"select *"))
    

    But the query isn't actually doing anything.

    So you could just use:

    =ArrayFormula({A2:B8,if(B2:B8<=3,D2:D8,C2:C8)})
    

    enter image description here