попробуй так:
=ARRAYFORMULA(IFERROR(VLOOKUP(A1:A,
{QUERY(QUERY(SPLIT(TRIM(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(IFERROR(SPLIT(B1:B, ","))<>"", "♦"&SPLIT(B1:B, ",")&"♠"&A1:A, ))
,,999^99)),,999^99), "♦"))), "♠"),
"select Col1,count(Col1) group by Col1 pivot Col2"), "select Col1 offset 1", 0),
SUBSTITUTE(REGEXREPLACE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(
QUERY(QUERY(SPLIT(TRIM(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(IFERROR(SPLIT(B1:B, ","))<>"", "♦"&SPLIT(B1:B, ",")&"♠"&A1:A, ))
,,999^99)),,999^99), "♦"))), "♠"),
"select count(Col1) group by Col1 pivot Col2"), "offset 1", 0)),
QUERY(QUERY(SPLIT(TRIM(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(IFERROR(SPLIT(B1:B, ","))<>"", "♦"&SPLIT(B1:B, ",")&"♠"&A1:A, ))
,,999^99)),,999^99), "♦"))), "♠"),
"select count(Col1) group by Col1 pivot Col2"), "limit 0", 1)&",", ))
,,999^99))), ",$", ), ", ", ",")}, 2, 0)))