If I have a sheet with data like this:

A    B
x    1
y    2
z    3
x    4

I can sum the values with

=query(A:B, "select A, sum(B) group by A")

How can I then filter this result? For example, in SQL to see x and y only (excluding z), I would add a WHERE clause like:

WHERE A IN ('x', 'y')

How can I get this functionality in a Sheets query?

1 Answer 1


Try this:

=query(A:B, "select A, sum(B) where A is not null and A <> 'z' group by A")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.