Array of Array issues

andyfleisher

New Member
Joined
May 25, 2011
Messages
9
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have some team data in the form below.


AB
1NameTeam
2Name 1Team 1
3Name 2Team 1
4Name 3Team 1
5Name 4Team 1
6Name 5Team 2
7Name 6Team 2
8Name 7Team 2
9Name 8Team 2
10Name 9Team 2
11Name 10Team 2
12Name 11Team 3
13Name 12Team 3
14Name 13Team 3
15Name 14Team 3
16Name 15Team 4
17Name 16Team 4
18Name 17Team 4
19Name 18Team 4
20Name 19Team 4
21Name 20Team 4

Is there a way, with a single formula to convert it to a more columnar format like below?


DEFG
1Team 1Team 2Team 3Team 4
2Name 1Name 5Name 11Name 15
3Name 2Name 6Name 12Name 16
4Name 3Name 7Name 13Name 17
5Name 4Name 8Name 14Name 18
6Name 9Name 19
7Name 10Name 20

I was initially using TRANSPOSE and UNIQUE to get the top row of team names

In cell D1: =TRANSPOSE(UNIQUE(B2:B21))

And then a FILTER function to get the names for Team 1.

In cell D2: =FILTER($A$2:$A$21,$B$2:$B$21=D1)

I then copied over the FILTER function in each column to look at each team name. Is there a way to do it all in a single function? I thought of using MAP, but that and FILTER don't seem to get along. Since each list of names per team can be a different length, I don't think I can use MAKEARRAY.

I have a current working solution but was just hoping to get better in my excel knowledge,

Thanks a lot!
 
try like this

Excel Formula:
=LET(un,UNIQUE(B2:B21),nm,A2:A21,tm,B2:B21,
IFERROR(VSTACK(TRANSPOSE(un),DROP(REDUCE("",un,LAMBDA(a,b,HSTACK(a,FILTER(nm,tm=b)))),,1)),""))


1741833537758.png
 

Attachments

  • 1741833259360.png
    1741833259360.png
    64.7 KB · Views: 3
Upvote 0
Solution
Try. In D1
Excel Formula:
=LET(a,A2:A21,b,B2:B21,hdr,UNIQUE(b),c,BYROW(hdr,LAMBDA(r,TEXTJOIN("_",1,FILTER(a,b=r)))),d,TEXTSPLIT(TEXTJOIN(",",0,c),"_",",",1,0,""),TRANSPOSE(HSTACK(hdr,d)))
 
Upvote 0
Another option
Fluff.xlsm
ABCDEFG
1NameTeam
2Name 1Team 1Team 1Team 2Team 3Team 4
3Name 2Team 1Name 1Name 5Name 11Name 15
4Name 3Team 1Name 2Name 6Name 12Name 16
5Name 4Team 1Name 3Name 7Name 13Name 17
6Name 5Team 2Name 4Name 8Name 14Name 18
7Name 6Team 2Name 9Name 19
8Name 7Team 2Name 10Name 20
9Name 8Team 2
10Name 9Team 2
11Name 10Team 2
12Name 11Team 3
13Name 12Team 3
14Name 13Team 3
15Name 14Team 3
16Name 15Team 4
17Name 16Team 4
18Name 17Team 4
19Name 18Team 4
20Name 19Team 4
21Name 20Team 4
22
Data
Cell Formulas
RangeFormula
D2:G8D2=LET(u,UNIQUE(TRIMRANGE(B2:B1000)),m,MAX(COUNTIFS(B:B,u)),DROP(REDUCE("",u,LAMBDA(x,y,HSTACK(x,VSTACK(y,EXPAND(FILTER(A2:A1000,B2:B1000=y),m,,""))))),,1))
Dynamic array formulas.
 
Upvote 0
A 2-step process:

Book11
DEFG
2Team 1Team 2Team 3Team 4
3Name 1Name 5Name 11Name 15
4Name 2Name 6Name 12Name 16
5Name 3Name 7Name 13Name 17
6Name 4Name 8Name 14Name 18
7Name 9Name 19
8Name 10Name 20
Sheet2
Cell Formulas
RangeFormula
D2:G2D2=TRANSPOSE(UNIQUE(B3:B22))
D3:D6,G3:G8,F3:F6,E3:E8D3=FILTER($A$3:$A$22,$B$3:$B$22=D2)
Dynamic array formulas.
 
Upvote 0
Another couple of options, using PIVOTBY:
Excel Formula:
=LET(
   data, SORT(TRIMRANGE(A2:B1000,2,0),2),
   name, TAKE(data,,1),
   team, DROP(data,,1),
   inum, SCAN(0,team=VSTACK("",DROP(team,-1)),LAMBDA(a,v,1+a*v)),
   DROP(PIVOTBY(inum,team,name,SINGLE,0,0,,0),,1)
)

Or GROUPBY:
Excel Formula:
=LET(
   a, DROP(GROUPBY(B2:B1000,A2:A1000,HSTACK(LAMBDA(v,TEXTJOIN("|",0,"",v,"")),ROWS),0,0,,B2:B1000<>""),1),
   n, TAKE(a,,-1),
   m, MAX(n),
   v, TEXTBEFORE(TEXTAFTER(INDEX(a,,2)&REPT("|",m-n),"|",SEQUENCE(,m)),"|"),
   TRANSPOSE(HSTACK(TAKE(a,,1),v))
)

Or an array reshaping option:
Excel Formula:
=LET(
   data, SORT(FILTER(A2:B1000,B2:B1000<>""),2),
   name, TAKE(data,,1),
   team, DROP(data,,1),
   u, UNIQUE(team),
   n, MMULT(--(TOROW(team)=u),EXPAND(1,ROWS(team),,1)),
   m, MAX(n),
   r, m-n,
   v, TOCOL(IFS(r>=SEQUENCE(,MAX(r)),u),2),
   i, ROWS(v),
   w, WRAPROWS(IF(ISERROR(i),name,SORTBY(EXPAND(name,ROWS(name)+i,,""),VSTACK(team,v))),m),
   TRANSPOSE(HSTACK(u,w))
)
 
Upvote 0
Here is another option using MAKEARRAY:
Excel Formula:
=LET(
   n,A2:A21,
   t,B2:B21,
   u,UNIQUE(t),
   m,MAX(COUNTIF(t,u)),
   VSTACK(TOROW(u),MAKEARRAY(m,ROWS(u),LAMBDA(r,c,IFERROR(INDEX(FILTER(n,t=INDEX(u,c)),r),""))))
)
 
Last edited:
Upvote 0
A 2-step process:

Book11
DEFG
2Team 1Team 2Team 3Team 4
3Name 1Name 5Name 11Name 15
4Name 2Name 6Name 12Name 16
5Name 3Name 7Name 13Name 17
6Name 4Name 8Name 14Name 18
7Name 9Name 19
8Name 10Name 20
Sheet2
Cell Formulas
RangeFormula
D2:G2D2=TRANSPOSE(UNIQUE(B3:B22))
D3:D6,G3:G8,F3:F6,E3:E8D3=FILTER($A$3:$A$22,$B$3:$B$22=D2)
Dynamic array formulas.
Thanks.

This is what I had originally done. It worked but I knew there had to be a single cell formula to figure it out as well
 
Upvote 0
Thanks everyone. It's nice to see that there are so many varied solutions. I think I understand most of them, and it's fun to break down the LET formulas to see how it is all working.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
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