Home > OS >  Using IF and WHERE ANY in Query() function
Using IF and WHERE ANY in Query() function

Time:02-01

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.

CodePudding user response:

add switch:

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