Search code examples
regexgoogle-sheetsgoogle-sheets-formulaarray-formulasgoogle-sheets-query

JOIN results of VLOOKUP into one string in Google Sheets


I have following task for my Google spreadsheet: JOIN strings in all cells that are to the right of certain id.

  • To phrase it differently: SELECT A, JOIN(',', B) GROUP BY A, WHERE A = myid; if JOIN was an aggregation function.
  • Or in other words: =JOIN(',', VLOOKUP(A:B, myid, 0)) if VLOOKUP could return all occurences, not just first one.
  • One picture better than of 1000 words:

enter image description here

Is this possible with Google Spreadsheets?


Solution

  • I believe you could use the FILTER function instead of VLOOKUP to filter a range based on an ID and then JOIN the returned range.

    The documentation for FILTER is here: https://support.google.com/docs/answer/3093197

    For example:

    • You put =UNIQUE($A:$A) in D2 to get all the IDs.
    • Then in E2 you put =IF($D2="", "", JOIN(",", FILTER($B:$B, $A:$A=$D2))) and then copy it down.