Mar 1, 2021
Flexible QUERY function - help with an MVP
Hello. I need some help with a QUERY formula that allows me to do dynamic searches, using as many arguments as necessary to obtain the result, but not being mandatory to use all of them.
To explain it better, let me show you how this spreadsheet will be used, which will serve as an MVP for an automated photosystem I'm building (hardware + software).
Imagine that I need to photograph a can of Budweiser. To get the best shot, I need to test a light scheme on the product until I find the ideal set - one that brings me the right brightness and volume in the image.
Well, the next time a similar beer can arrive to be photographed, I would like to have this light set stored so that I can quickly set the ideal light without wasting time. This is the hypothesis to be validated.
So, let's see, the ideal light for a Budweiser can be used for all products that have the same characteristics (which we call attributes):
- Metal
- Can
- Round
- Soft colors
- Reflective material
What I need is to be able to filter which preset is ideal to use at that moment, allowing me to see all the options available as I choose the attributes:
For example, I want to see all the saved presets for metal products > cans > round - so I can decide which one most closely matches the situation I need.

=ArrayFormula(QUERY({Presets_database!B1:AK};"select * where Col2 matches """&K9&""" AND Col3 matches """&L9&""" order by Col1 desc ";1))
However, my knowledge of QUERY does not allow me to filter all metal products that are round, as the "Type" attribute has not been provided - causing the search to return blank:

=ArrayFormula(QUERY({Presets_database!B1:AK};"select * where Col2 matches """&K9&""" AND Col3 matches """&L9&""" AND Col4 matches """&M9&""" order by Col1 desc ";1))
I have tried OR statement but that's not it yet. I think what I need is a mix of AND & OR that allows me to use or not an attribute to get the result. Or, in other words, use any attribute I want to display the result.
Is that possible?
Another example of a search that would be excellent to have available: I want to see all presets for beer, typing on
U9
(no matter if it's a glass or a metal package).I hope I managed to be clear.
QUERY() formula is on
J11
.Here:
Community content may not be verified or up-to-date. Learn more.
Last edited Mar 1, 2021
All Replies (6)