Search code examples
google-sheetsgoogle-sheets-formula

Repeat a formula in google sheet within a single cell using different values


So to summarize what i want: Let's say i have

   A         B
1 "Tommy"    "1,2,3"
2 "Berry"    "3,4,5"
3 "Hank"     "1,4,5"
4
5
6 "1"        
7 "5"

I would like B6 to show "Tommy Hank" and B7 to show "Berry Hank"

If have managed to create this formula;

=IF(ISERROR(MATCH($A6,SPLIT(B1, "," , 1,1),0)),"",A1)

This formula will give me back the value "Tommy" but not Hank.

I want to list all corresponding A values for every B cell that contains the value "1".

I tried some things with arrayformula like =IF(ISERROR(MATCH($A6,SPLIT(B1:B3, "," , 1,1),0)),"",A1:A3) but i don't really understand what i'm doing here.


Solution

  • I was going to suggest

    =ArrayFormula(
       textjoin(" ",,
         query(
           {A$1:A$3,","&B$1:B$3&","},
           "select Col1 
            where Col2 contains'"&","&A6&","&"'"
         )
       )
     )
    

    enter image description here