Search code examples
google-sheetsdate-rangegoogle-sheets-query

Google sheets query with date range stopped working after functioning perfectly for months


The following query was working just fine a few weeks ago. When I went back to look at the query data today it has stopped returning anything but the header row.

=QUERY({'2BiWeeklyGCBBuildInvoices'!A:N},"Select * where Col4 >= ' "&text(P2,"mm/dd/yyyy")&" ' and Col4 <= ' "&text(Q2,"mm/dd/yyyy")&" ' ")

I made no changes. The only thing I can think of is the last time I saw it working was in Dec 2018. Now it's Jan 2019. Did this break my query? I've tried many different solutions like changing the date format in the query data and in the date that is referenced in the query.


Solution

  • It's hard to say without having the underlying data available, but from the look of the query and the description of the behavior you're giving, I'd say that:

    1. The formula is comparing text strings rather than dates
    2. The format of those text strings is "mm/dd/yyyy"
    3. Which means that 01/05/2019 appears to be before 12/01/2018, which seems to be giving you your trouble

    If you want to be able to compare strings that are made up of dates, they must be in a format starting with the most significant values first and working towards the least significant, e.g. "yyyy/mm/dd". You say you've tried different date formats, but keep in mind that you need to format the text on both sides of the expression, so both in Col4 and in P2 and in Q2.

    The other item that may be causing an issue is that this is an array formula, and in general you must enter them by pressing CTRL+SHIFT+ENTER instead of just pressing enter. If nothing uses the current date and the values have not updated, that's likely the issue.