Search code examples
google-sheetsgoogle-query-language

Google Sheets Query Function - Where column not equal to a specific range of cells


Got a query running in google sheets that is filtering a large range of data down into a short list with items in a specific order.

=Query('2022'!$B2:$O,"Select H,B,E,O where M = date '"&TEXT(DATEVALUE($N$1),"yyyy-mm-dd")&"' And (H Contains '"&P1&"' or H Contains '"&P2&"' or H Contains '"&P3&"' or H Contains '"&P4&"') Order by O asc",0)

I'm trying to add another "where" condition

And B != '"&A2:A30&"'

But adding this condition doesn't work. Am I missing something obvious or is this not possible? I can get it to work by typing a single value in the query, but it wont work with a cell reference or a range of cell references


Solution

  • You can try with "matches" condition and TEXTJOIN:

       ..."AND not B matches '\b"&TEXTJOIN("\b|\b",1,A2:A30)&"\b' ...."