Using IF and WHERE ANY in Query() function

Viewed 29

I have the following query function that displays data based on the selection of two dropdown cells:

=QUERY('Rates Master'!A1:G,"SELECT * WHERE YEAR(A) = "&B1&" AND F = '"&B2&"'",1)

Cell B1 consists of:

Any
2019
2020
2021

I would like to modify my query that:

If "Any" is selected, entries with any date are displayed.

I'm completely stumped though - would greatly appreciate any guidance on how to formulate this correctly.

1 Answers

add switch:

=QUERY('Rates Master'!A1:G,
 "where 1=1"& 
  IF(B1="",, " and YEAR(A) = "&B1&")& 
  IF(B2="",, " and F = '"&B2&"'"), 1)
Related