google-sheetsgoogle-sheets-formula

QUERY Formula referring to the value of a cell rather than a constant piece of text


I am trying to use a query formula that refers to the value of a cell rather than a constant piece of text.

Here is an example:

=QUERY(A2:E, "Select A where E = 'California'")

It basically picks all values that have California in column E. But instead, I would like to use this query formula to refer to a cell that contains the desired text rather than a constant piece of text. I basically don't want to write text in every formula, but rather just change it in one cell and have it change all the formulas.

So I tried this:

=QUERY(A2:E, "Select A where E = 'G12'")

But it doesn't work. How do I add a cell to this formula?


Solution

  • You may try:

    =query(A2:E,"Select A Where E = '"&G12&"'")