Search code examples
google-sheetsgoogle-sheets-formulagoogle-query-language

Exclude all values in a column on a different sheet from a Google Sheets Query


So I have the following query:

=QUERY('sheet - Users'!A1:S, "Select A,B,C,F,G,O,Q,S where Q >= 44223 and not lower(O) matches '.*archived.*|.*archived' and not lower(C) matches '.*admin.*|.*admin' and not UPPER(C) matches '.*SMB.*' and not C matches '.*Shared Mailbox.*' and S >=90",1)

This works perfectly fine (as convoluted as it is), however, I have a list of exceptions that I need to remove from the results (the list could change, so ideally this needs to be dynamic and not hard coded).

I did some digging around and found this example query:

=query(C2:C8,"select C where C<>'"&JOIN("' and C<>'",D2:D10)&"'"&""

But that doesn't seem to be working for me when I try to incorporate it into my query.

The data I need to exclude is on a sheet called: Exclusion List And is in cells C2:C

Is anyone able to help?


Solution

  • Solution:

    You can modify the exclusion list to reference C2:C from another sheet, like this:

    =query(C2:C8,"select C where C<>'"&JOIN("' and C<>'",'Exclusion List'!C2:C)&"'"&""
    

    Sample Query and Exclusion Sheet:

    enter image description here

    enter image description here