0

I am trying to match a single value in a cell with content of a comma-separated list in a cell in multiple rows and get all matches returned in a comma-separated list.

The source data sheet format looks like:

enter image description here

Function ID Test ID
769356 DAB-CTRL-TI-861
768859 DAB-CTRL-TI-164, DAB-CTRL-TI-196, DAB-CTRL-TI-83
769366 DAB-CTRL-TI-861
768709 DAB-CTRL-TI-861

and I want to get a sheet that has a unique row per "Test ID" containing each match as a comma-separated list for column "Function ID" that looks like:

enter image description here

Test ID Function ID
DAB-CTRL-TI-861 769356, 769366, 768709
DAB-CTRL-TI-164 768859
DAB-CTRL-TI-196 768859
DAB-CTRL-TI-83 768859

In the second sheet column "Function ID" I have tried the following formula but it only matches the first occurrence and also makes false matches when the list contains substrings, e.g. matches DAB-CTRL-TI-8 when it should match DAB-CTRL-TI-88 so using a partial match for values in the list when it should make an exact match per list entry.

=VLOOKUP("*"&B2&"*",Sheet1!A:B,2,FALSE)

3 Answers 3

0

Here is one way you could try using TEXTJOIN()+FILTER()+REGEXTEST()+MAP()

enter image description here


=MAP(A8:A11, LAMBDA(x, TEXTJOIN(", ", 1, FILTER(A2:A5, REGEXTEST(", "&B2:B5&", ", ", "&x&", ")))))

Or,

=TEXTJOIN(", ", 1, FILTER(A$2:A$5, 1-ISERR(SEARCH(", "&A8&", ", ", "&B$2:B$5&", ")), ""))
Sign up to request clarification or add additional context in comments.

Comments

0

With Office 365 functions the below formula

  • a contains the unique values of Test ID
  • b execute a LAMBDA function on the a elements, which collects the Function ID of the corresponding row where the Test ID is found
  • Last row generate the result table display the two columns side-by-side.
=LET(a,UNIQUE(TEXTSPLIT(TEXTJOIN(",",TRUE,B2:B5),,",")),
b,MAP(a,LAMBDA(x,TEXTJOIN(",",TRUE,IF(IFERROR(SEARCH(","&x&",",","&B2:B5&","),0),A2:A5,"")))),
HSTACK(a,b))

Comments

0

Here is a different approach using custom LIKE function using LAMBDA().

=TEXTJOIN(",",1,FILTER($A$2:$A$5,LIKE($B$2:$B$5,"*"&E2&"*")))

LIKE function signature is as following-

LIKE =LAMBDA(range,criteria,[and_or],LET(fnλ,IF(TYPE(criteria)=64,LET(and_or,IF(ISOMITTED(and_or),OR,and_or),LAMBDA(rng,and_or(COUNTIF(rng,criteria)))),LAMBDA(rng,COUNTIF(rng,criteria))),BYROW(range,fnλ)))

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.