Search code examples
google-sheetsgoogle-query-language

Compare dates in WHERE request within QUERY in GoogleSheets


I'm trying to query a range that returns only rows where the date in Column S is older than the date in Column D

All dates in the sheet are already formatted yyyy-mm-dd but I can't seem to find any suggestions on how to use WHERE with a range of dates, rather than either a single date or a specific cell.

=QUERY(Sheet1!A2:W11536,"select A,B,C,D,E,F,G,H,I,J,K where date '"&text(Sheet1!D2:D,"yyyy-mm-dd")&"' > date'"&text(Sheet1!S2:S,"yyyy-mm-dd")&"'")

This is giving me an N/A error: "Query completed with an empty output."

When I make it < rather than > it populates without error, though it's not showing the desired results. There should be valid data for >.

Thanks!


Solution

  • I think this is enough when you're comparing two columns

    =query(A:H,"select A,B,C,D,E,F,G,H where C>H")
    

    (although I couldn't find any rows that satisfied the criteria in your test sheet)

    I think what is actually happening is that it is just comparing the first two dates so you either get all of the data or nothing.