saj01
saj01

Reputation: 31

Google Sheets Query with Logic Statements

I am trying to create a list of data from a data range in Google Sheets. I thought of using the query function, but with that, you can't seem to use regular logical statements.

I know that this snippet of code is wrong and doesn't work, but hopefully it makes it clear what I'm trying to do.

=Query(E2:E103, OR(AND(D2:D103=A$2,G2:G103=A$5),AND(D2:D103=A$3,G2:G103=A$5),D2:D103=A$1))

In this code, A$2, A$5, A$3, and A$1 are all just string variables in the corresponding cells that tell the logic statement what to compare.

If there is another way to write this or a different function that accomplishes what I would like to do, it would be greatly appreciated if you could share it with me.

Upvotes: 1

Views: 569

Answers (1)

Max Makhrov
Max Makhrov

Reputation: 18727

Basic case

The basic syntax for building a query logic:

"where F = '" & A1 & "'"

  • assumes A1 is a string, values in column F are strings
  • adds single quotes, makes the resulting query string: where F = 'sample text'

Logic

Your case looks like this:

where (A) or (B) or C =>

where (A1 and A2) or (B1 and B2) or C =>

where (D = 'text1' and G = 'text2') or (D = 'text3' and G = 'text4') or D = 'text5'

Upvotes: 1

Related Questions