Vlookup on multiple values in a cell

107 views Asked by At

I would like to be able to return [cat,dog] as shown in column B. This is more of a POC, but for the main challenge I am facing, there will be an unknown number of values in cell A1. I'm not sure if there is a way to do this with a vlookup, or if there is a better way to do this.

enter image description here

2

There are 2 answers

1
player0 On

use:

=ARRAYFORMULA("["&TEXTJOIN(",", 1, 
 IFERROR(VLOOKUP(FLATTEN(SPLIT(A1, "[,]", 1, 0)), A3:B, 2, 0)))&"]")

enter image description here

0
kishkin On

Guessing there could be more then one canine species (dog, dog2, ...) and all should be returned:

= "["
& JOIN(
    ",",
    QUERY(
      A3:B11,
      "SELECT B
       WHERE A MATCHES '^(?:" & JOIN("|", UNIQUE(SPLIT(A1, "[,]"))) & ")$'
       ORDER BY B",
      0
    )
  )
& "]"

We just filter out everything that does not match the regular expression ^feline|canine|...$ with QUERY using MATCHES and join it with commas.

Regular expression is constructed in this (just unique words joined by |):

'^(?:" & JOIN("|", UNIQUE(SPLIT(A1, "[,]"))) & ")$'

enter image description here