Excel formula to find value in multiple dynamic arrays

radub

New Member
Joined
Sep 27, 2013
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Good evening,
i've been struggling to find a solution to this, but no solution so far :|
Is there a chance I can use Excel 365 formula to find a value in multiple dynamic arrays, and return the array name?
Something like this :

dARR1: one, two , three
dARR2: two, three, five, eight, dARR1
dARR3: two, six, dARR2
dARR4: eight, nine, three, one, two, dARR3
dARR5: two, five, one, six

result:
six: belongs to dARR3, dARR4, dARR5

Thank you,
 
Hi Jim & sorry for overcomplicating things.
I've put this another way, maybe I'll manage to explain it better
I have many groups of people and I'm trying to determine the group(s) each person belongs to.
The tricky part is when groups are nested in another groups like bellow:


Book1
AB
1initial data
2groupNameMembers
3group1John, Anne, Marie
4group2Josh,Alex,group1
5group3Adele,Ema
6group4Keith,Ed,Scott,group2
7group5Valerie,Luci,group4
8
9
10RESULT
11PersonGroup(s)
12Emagroup3
13Alexgroup2, group4, group5
14Johngroup1, group2, group4, group5
Sheet1


Thank you,
actually, the real data are in table I pasted earlier but it's not very obvious, so I used the person names to make it a little bit more clear. If you can set me on the right track using the person names data, I hope I can take it from there. I paste below the data from above, removing the additional info, so it is in same format as the personal names example
Thank you,
Book1
AB
1groupNameMembers
2HELX_SL_TTHX-SL-01-TT
3HELX_SO_TTHX-SSO-01-TT
4HELX_WB_TTHX-WB-01-TT;HX-WB-02-TT
5HR_SL_TTTHR-SL-01-TT;HELX_WB_TT
6IM_WB_UTIM-WB-01-UT;IM-WB-02-UT;IM-PP-03-UT;IM-PP-04-UT
7IN_CCK_PP_DVIS-PP-01-DV;IS-PP-04-DV;IS-PP-02-DV;IS-PP-03-DV;IS-PP-05-DV;IS-PP-06-DV
8IMAN_PP_DVICE-PP-01-DV;IM_WB_UT
9IMAN_PP_UTICE-PP-01-UT
10IPDS_PP_TTSLW-PP-01-TT;HELX_WB_TT
11JA_PP_TTJIR-PP-02-TT;JIR-PP-03-TT;IMAN_PP_DV;HELX_WB_TT
12JP_TS_ENI_DCCBS-VN-01-PD;TS-VN-01-PD;TS-VN-02-PD;TS-VN-03-PD;TS-VN-04-PD;TS-VN-05-PD;TS-VN-06-PD;TS-VN-07-PD;TS-VN-08-PD;TS-VN-09-PD;TS-VN-10-PD;TS-VN-11-PD;TS-VN-12-PD;TS-VN-14-PD
13KX_PP_TTKFX-PP-02-TT;KFX-SCN-02-TT;IPDS_PP_TT
Sheet2
 
Upvote 0
I am SLOWLY trying to get you some help. No promises.

Does each member only appears once in the members data (not including group names)?

Will there ever be a group with no members?

Are members always separated by semicolons.
 
Upvote 0
Another question...Is it possible thata higher indexed group will be listed as part of a lower indexed group. For example, might group 5 be part of group 1?
 
Upvote 0
I am SLOWLY trying to get you some help. No promises.

Does each member only appears once in the members data (not including group names)?

Will there ever be a group with no members?

Are members always separated by semicolons.
Thank you for your help, Jim! I really apreciate!

1. Does each member only appears once in the members data (not including group names)? -- yes
2. Will there ever be a group with no members? -- no
3. Are members always separated by semicolons. --yes
 
Upvote 0
Based on your example with names does this help??
Book1
AB
1initial data
2groupNameMembers
3group1John, Anne, Marie
4group2Josh,Alex,John,Anne,Marie
5group3Adele,Ema
6group4Keith,Ed,Scott,Josh,Alex,John,Anne,Marie
7group5Valerie,Luci,Keith,Ed,Scott,Josh,Alex,John,Anne,Marie
8
9
10RESULT
11PersonGroup(s)
12Emagroup3
13Alexgroup2:group4:group5
14Johngroup1:group2:group4:group5
Sheet3
Cell Formulas
RangeFormula
B12:B14B12=TEXTJOIN(":",,FILTER($A$3:$A$7,REGEXTEST($B$3:$B$7,A12,1)))
 
Upvote 0
Not sure if this is what you're looking for, but you could try the following:
Excel Formula:
=LET(
   rng, A3:B7,
   grp, TAKE(rng,,1),
   fnλ, LAMBDA(me,mbr,LET(
      inc, BYROW(ISNUMBER(SEARCH(grp,TOROW(mbr))),OR),
      IF(OR(inc),me(me,REDUCE(mbr,FILTER(grp,inc),LAMBDA(a,v,SUBSTITUTE(a,v,XLOOKUP(v,grp,mbr))))),mbr))),
   txt, fnλ(fnλ,TAKE(rng,,-1)),
   arr, TEXTSPLIT(TEXTAFTER(";"&txt,";",SEQUENCE(,MAX(LEN(txt)-LEN(SUBSTITUTE(txt,";",)))+1)),";"),
   GROUPBY(TOCOL(arr,2),TOCOL(IF(ISERROR(arr),arr,grp),2),ARRAYTOTEXT,0,0)
)

fnλ is a recursive lambda function that replaces any group names found in the members list with their corresponding member names and repeats until all subsequent group names are also replaced.

The final result will be a list of all member names with their corresponding groups. You could also use the optional [filter_array] argument of GROUPBY, if desired, to return specific names only; e.g: ISNUMBER(XMATCH(TOCOL(arr,2),{"Alex";"Ema";"John"}))
 
Upvote 0
Revised without recursion, but by using the accumulated results (a) as the return_array instead:
Excel Formula:
=LET(
   rng, A3:B7,
   grp, TAKE(rng,,1),
   mbr, TAKE(rng,,-1),
   txt, REDUCE(mbr,FILTER(grp,BYROW(ISNUMBER(SEARCH(grp,TOROW(mbr))),OR)),LAMBDA(a,v,SUBSTITUTE(a,v,XLOOKUP(v,grp,a)))),
   arr, TEXTSPLIT(TEXTAFTER(";"&txt,";",SEQUENCE(,MAX(LEN(txt)-LEN(SUBSTITUTE(txt,";",)))+1)),";"),
   GROUPBY(TOCOL(arr,2),TOCOL(IF(ISERROR(arr),arr,grp),2),ARRAYTOTEXT,0,0)
)

Also, as an alternative to return the results for the list of names in range A12:A14 only:
Excel Formula:
=LET(
   rng, A3:B7,
   grp, TAKE(rng,,1),
   mbr, TAKE(rng,,-1),
   txt, REDUCE(mbr,FILTER(grp,BYROW(ISNUMBER(SEARCH(grp,TOROW(mbr))),OR)),LAMBDA(a,v,SUBSTITUTE(a,v,XLOOKUP(v,grp,a)))),
   MAP(A12:A14,LAMBDA(v,ARRAYTOTEXT(FILTER(grp,ISNUMBER(SEARCH(v,txt))))))
)

Hopefully one of these can be adapted to meet your needs. Cheers!
 
Upvote 0
One more variation, just for good measure...
Excel Formula:
=LET(
   rng, A3:B7,
   grp, TAKE(rng,,1),
   mbr, TAKE(rng,,-1),
   txt, REDUCE(mbr,SEQUENCE(ROWS(rng)),LAMBDA(a,v,SUBSTITUTE(a,INDEX(grp,v),INDEX(a,v)))),
   arr, TEXTSPLIT(TEXTAFTER(";"&txt,";",SEQUENCE(,MAX(LEN(txt)-LEN(SUBSTITUTE(txt,";",)))+1)),";"),
   GROUPBY(TOCOL(arr,2),TOCOL(IF(ISERROR(arr),arr,grp),2),ARRAYTOTEXT,0,0)
)
-OR-
Excel Formula:
=LET(
   rng, A3:B7,
   grp, TAKE(rng,,1),
   mbr, TAKE(rng,,-1),
   txt, REDUCE(mbr,SEQUENCE(ROWS(rng)),LAMBDA(a,v,SUBSTITUTE(a,INDEX(grp,v),INDEX(a,v)))),
   MAP(A12:A14,LAMBDA(v,ARRAYTOTEXT(FILTER(grp,ISNUMBER(SEARCH(v,txt))))))
)
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top