Search code examples
google-sheetsgoogle-query-language

Query - multiple criteria with dates - Not expected output


I have this query function:

=query('Database'!A1:AD979,"select* where (F < date """&text(today(),"yyyy-MM-dd")&""") or (J <  date """&text(today(),"yyyy-MM-dd")&""") or (U = 'Terminated')")

From my understanding, this function should select any row that matches at least one of the criteria in the query. Yet, the result of this query also shows rows that do not meet any of these criteria.

Do you have any idea / explanations?

Thks in advance


Solution

  • See if this works

    =query('DataBase'!A1:AD979, "select* where F < date '"&text(today(),"yyyy-MM-dd")&"' or J <  date '"&text(today(),"yyyy-MM-dd")&"' or U = 'Terminated'", 0)
    

    Note: it may be possible to exclude also rows with empty cells in F and J? In that case, try

    =query('DataBase'!A1:AD979, "select* where (F < date '"&text(today(), "yyyy-MM-dd")&"' AND F is not null) or (J <  date '"&text(today(), "yyyy-MM-dd")&"' and J is not null) or U = 'Terminated'", 0)