2

I'm working on a google spreadsheet and have to do a dropdown list depending on some criteria. For example I have a DB page with :

|   A  |   B   |
| name | price |
| a    | 100   |
| b    | 120   |
| c    | 150   |

If I want to get a list of all item I know I can do it with the formula, going to data > validation and say the range DB!A3:A999 as explained here : https://support.google.com/docs/answer/186103

Now I would like to add some possible filter for the user like min & max price.

I think I need to use the query formula like =QUERY(DB!3:999, "SELECT A WHERE B>=110 AND B<=140") but this is returning all correct result in all case under where I put the formula (1 row = 1 result). Is there a way to turn this query into a dropdown list ? or any other way to add criterias to the validation range ?

EDIT

Here is a spreadsheet link if you want to test your solution before posting https://docs.google.com/spreadsheets/d/1mwgBla7DyIHio8eH3xr2w_EngvHcHIeTXwc43e7YwwU/edit?usp=sharing

1 Answer 1

4
+50

Yes, you can do something like this:

Say cell B1 is a dropdown list you can write your query:

=QUERY(DB!3:999, "SELECT A WHERE B='"&B1&"' ")

However this will only work with plain text.

I think the better option fro you would be to use FILTER formula.

4
  • 1
    My problem is here... how can I say B1 is a dropdown list with the value from the query "...". If I go to data > validation I can choose from range (which means no filter) or from personnal formula. The second is the good one I think, but it disable the "show as list" option, and the formula doesn't work... I just edit to add a spreadsheet link if you want to test
    – Luckyn
    Jul 27, 2015 at 9:17
  • Also query work even with number, but you should not add quote for them :)
    – Luckyn
    Jul 27, 2015 at 9:33
  • 1
    Sorry, my bad. I made a copy of your filter sheet in that spreadsheet, check it. Basically you can do that. If there will be many rows, you can push all the validation rules via script instead of doing each row manually. Jul 27, 2015 at 9:39
  • I didn't thought about using "temporary case" from query to create a range, then use this range to do the list :) I'll wait a bit more to see if someone know a direct formula for the list, else I'll just use your solution and "hide" query in a corner :)
    – Luckyn
    Jul 27, 2015 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.