google-sheetslookup

How to lookup multiple values at once in a table and return a single column


I have a table that lists car brands (Ford, GM, Toyota, etc) and their corresponding models that we have in inventory. See link below. I can use Query to pull up all models from a given Brand (say, Ford). But I can't pull up all models that belong to more than one brand (say, Ford and Toyota). The query gives an error "Result should be a single row." Is there a way to do multi-value lookup using any function, including Query, lookup, Filter, etc.? See sample file enter image description herelink here: https://docs.google.com/spreadsheets/d/1THOX8kprtx7xHMIpby1Gz9KBB5XrjBUcc0INkl__1lg/edit?usp=sharing

Thank you.


Solution

  • One way is to use a regular expression in query(), like this:

    =query(Sheet1!A1:B, "where Col1 matches '^(Honda|Ford)$' ", 1)
    

    With filter(), you can use Boolean arithmetic, like this:

    =filter(A2:B, (A2:A = "Honda") + (A2:A = "Ford"))
    

    See query() and filter().