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

Referencing a cell in query function not included in range in google sheets


I'm trying to write a query function that selects a value from a column on a different sheet where a different column from the same sheet is equal to a cell on the target sheet.

Here's my attempt at trying to show this with code:

=QUERY(OtherSheet!D:E,"Select E where (D = D8)")

D8 is the cell from the target sheet that I want to reference.


Solution

  • should be:

    =QUERY(OtherSheet!D:E, "select E where D = "&D8)
    

    if D8 is a numeric value


    otherwise, if D8 is plain text it should be:

    =QUERY(OtherSheet!D:E, "select E where D = '"&D8&"'")