# One Dynamic Array Formula

February 25, 2020 - by Bill Jelen

Note

This is one of a series of articles detailing solutions sent in for the Podcast 2316 challenge.

YouTuber Rico S took a completely different approach. His table is generated by a single dynamic array formula.

The Total in O is not filling in. If you had Charles Williams Speed Tools V4, you could wrap Rico’s formula in TOTALS as shown below.

Posted here, without further comment, is Rico’s formula in I13:

=CHOOSE({1,2,3,4,5,6},LEFT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)-1),RIGHT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),LEN(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1))-FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)),INDEX(UglyData,MATCH(LEFT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)-1),\$A\$3:\$A\$9,0),MATCH(RIGHT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),LEN(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1))-FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)),\$A\$3:\$Z\$3,0)+1),INDEX(UglyData,MATCH(LEFT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)-1),\$A\$3:\$A\$9,0),MATCH(RIGHT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),LEN(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1))-FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)),\$A\$3:\$Z\$3,0)+2),INDEX(UglyData,MATCH(LEFT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)-1),\$A\$3:\$A\$9,0),MATCH(RIGHT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),LEN(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1))-FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)),\$A\$3:\$Z\$3,0)+3),INDEX(UglyData,MATCH(LEFT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)-1),\$A\$3:\$A\$9,0),MATCH(RIGHT(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),LEN(INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1))-FIND(":",INDEX(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee"),INT(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1)/4+1),MOD(SEQUENCE(COUNTA(\$A\$4:\$A\$9&":"&FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),1,0,1),4)+1),1)),\$A\$3:\$Z\$3,0)+4))

Update! Above, I used the Charles Williams HTOTALS function to improve on Rico’s formula. Rico dove into the documentation for the FastExcel add-in and found two amazing functions: SETMEM and GETMEM. You can optimize your formulas by storing and retrieving the results of very calculation-intensive expressions used more than once in a formula. This is a ground-breaking function.

Rico used it to reduce his 6,866-character formula to a 593-character formula:

=HTOTALS(CHOOSE({1,2,3,4,5,6},SETMEM(LEFT(SETMEM(LISTDISTINCTS(TRANSPOSE(\$A\$4:\$A\$9)&":"&TRANSPOSE(FILTER(\$A\$3:\$Z\$3,LEFT(\$A\$3:\$Z\$3,8)="Employee")),,,FALSE),"A"),FIND(":",GETMEM("A"),1)-1),"B"),SETMEM(RIGHT(GETMEM("A"),LEN(GETMEM("A"))-FIND(":",GETMEM("A"),1)),"C"),INDEX(UglyData,MATCH(GETMEM("B"),\$A\$4:\$A\$9,0)+1,MATCH(GETMEM("C"),\$A\$3:\$Z\$3,0)+1),INDEX(UglyData,MATCH(GETMEM("B"),\$A\$4:\$A\$9,0)+1,MATCH(GETMEM("C"),\$A\$3:\$Z\$3,0)+2),INDEX(UglyData,MATCH(GETMEM("B"),\$A\$4:\$A\$9,0)+1,MATCH(GETMEM("C"),\$A\$3:\$Z\$3,0)+3),INDEX(UglyData,MATCH(GETMEM("B"),\$A\$4:\$A\$9,0)+1,MATCH(GETMEM("C"),\$A\$3:\$Z\$3,0)+4)))

Read more about SETMEM and GETMEM here.

Charles Williams checked in and suggested this formula:

=HTOTALS(VSTACK(HSTACK(,A4:A9,G3,SLICES(A4:AB9,0,H4:K4)),HSTACK(,A4:A9,L3,SLICES(A4:AB9,0,M4:P4)),HSTACK(,A4:A9,Q3,SLICES(A4:AB9,0,R4:U4)),HSTACK(,A4:A9,V3,SLICES(A4:AB9,0,W4:Z4))))

On March 19, 2020 after the LET function debuted in Excel, Rico S sent in this shorter formula. This currently requires Office 365 with Insiders Fast.

=LET(
_splitChar,"~",
_categories,\$A\$4:\$A\$9,
_colHdrs,\$A\$3:\$Z\$3,
_employees,FILTER(_colHdrs,LEFT(_colHdrs,8)="Employee"),
_unique2DTable,_categories&_splitChar&_employees,
_cntE,COUNTA(_employees),
_cnt,COUNTA(_unique2DTable),
_uniqueList,INDEX(_unique2DTable,INT(SEQUENCE(_cnt,1,0,1)/_cntE+1),MOD(SEQUENCE(_cnt,1,0,1),_cntE)+1),
_category,LEFT(_uniqueList,FIND(_splitChar,_uniqueList,1)-1),
_employee,RIGHT(_uniqueList,LEN(_uniqueList)-FIND(_splitChar,_uniqueList,1)),
_row,MATCH(_category,_categories,0)+1,
_col,MATCH(_employee,_colHdrs,0),
_Q1,INDEX(UglyData,_row,_col+1),
_Q2,INDEX(UglyData,_row,_col+2),
_Q3,INDEX(UglyData,_row,_col+3),
_Q4,INDEX(UglyData,_row,_col+4),
_totalCol,INDEX(UglyData,_row,_col),
_finalTable,CHOOSE({1,2,3,4,5,6,7},_category,_employee,_Q1,_Q2,_Q3,_Q4,_totalCol),
SORT(_finalTable,2)
)

Return to the main page for the Podcast 2316 challenge.

To read the next article in this series: Old School Helper Columns.

##### Bill Jelen is the author / co-author ofExcel Insights – A Microsoft MVP Guide to the Best Parts of Excel

There are fewer than 100 Excel MVPs worldwide. 24 of them have contributed to this book. Written, edited, reviewed and printed by Excel MVPs, this is practical Excel passion undiluted, with each MVP highlighting some of their favorite topics.