functiongoogle-sheetsformulamultiple-conditions

QUERY function with multiple conditions using time frame


I have this query that I am trying to add a condition to to filter out the results of a report given a time frame (time frame in my sheet is N2 and N3)

What I have now is the following and it works like a charm:

=QUERY('Report'!$A$2:$I; "Select B Where A = '"&$B28&"'");"Nothing to show")

No I want to add a condition to filter out only the results given my time period in N2 (start date) and N3 (end date). My dates in the reports are in column D. I did the following but it's not working:

=QUERY('Report'!$A$2:$I; "Select B Where A = '"&$B12&"';Select D where D >= date '"&$N$2&"' and D <= date '"&$N$3&"'");"Nothing to show")

What am I doing wrong?


Solution

  • Your query syntax is wrong. Try the following QUERY() formula-

    =QUERY('Report'!$A$2:$I; "Select B Where A = '"&$B12&"' and D>= date '" &TEXT(N2,"yyyy-mm-dd")& "' and D<= date '" & TEXT(N3,"yyyy-mm-dd") & "'",1)