schardt679
Board Regular
- Joined
- Mar 27, 2021
- Messages
- 58
- Office Version
- 365
- 2010
- Platform
- Windows
- Mobile
- Web
ASTACK stacks or unstacks an array going row by row or column by column given a number of columns.
Thanks to Rico's ARRAY2DTO1D & ARRAY1DTO2D functions and XLambda's older ASTACK & AUNSTACK functions for the inspiration.
It combines the functionality of an array stacking function and an array unstacking function.
If Stack_Into < array columns, the array is stacked. If Stack_Into > array columns, the array is unstacked
If skipping arguments, a comma is required. Calls IFBLANK, CELLCOUNT, & AINDEXERL.
Other functions on minisheet: AFORMULATEXT.
Screen Tip/ Comment: =ASTACK(Array☛ range to stack/unstack, [Stack_Into]☛ number of columns to stack/unstack into; 0/=1, [By_Col]☛ 1=stack/unstack column by column; 0/=row by row) ⁂[]=optional; =default; =omit
Thanks to Rico's ARRAY2DTO1D & ARRAY1DTO2D functions and XLambda's older ASTACK & AUNSTACK functions for the inspiration.
It combines the functionality of an array stacking function and an array unstacking function.
If Stack_Into < array columns, the array is stacked. If Stack_Into > array columns, the array is unstacked
If skipping arguments, a comma is required. Calls IFBLANK, CELLCOUNT, & AINDEXERL.
Other functions on minisheet: AFORMULATEXT.
Screen Tip/ Comment: =ASTACK(Array☛ range to stack/unstack, [Stack_Into]☛ number of columns to stack/unstack into; 0/=1, [By_Col]☛ 1=stack/unstack column by column; 0/=row by row) ⁂[]=optional; =default; =omit
Excel Formula:
=LAMBDA(Array,[Stack_Into],[By_Col],
LET(Arr, IFBLANK(Array, ""), Into, IFERROR(--(Stack_Into),), Col?, By_Col,
IntoScan, Into<0, IntoMSG, "Stack_Into>=0",
ColScan, AND(Col?<>{1,0}), ColMSG, "By_Col=1,0",
ERRORS, IFS(IntoScan, IntoMSG, ColScan, ColMSG, 1, 0),
RowSeq1, AINDEXERL(Arr,, Col?), ColSeq1, AINDEXERL(Arr, 1, Col?),
STACK, INDEX(Arr, RowSeq1, ColSeq1), TotCt, CELLCOUNT(Arr),
ColCt, MAX(Into, 1), RowCt, ROUNDUP(TotCt / ColCt,),
RowSeq2, SEQUENCE(RowCt, ColCt), ColSeq2, TRANSPOSE(SEQUENCE(ColCt, RowCt)),
Seq, IF(Col?, ColSeq2, RowSeq2), UNSTACK, INDEX(STACK, Seq),
Result, IF(Seq>TotCt, "", UNSTACK), Return, IF(ERRORS<>0, ERRORS, Result),
Result
)
)
LAMBDA Examples.xlsx | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | |||
1 | ASTACK | |||||||||||||||
2 | ||||||||||||||||
3 | Original Data | Stack_Into: | Result | |||||||||||||
4 | Product | Sales | By_Col: | Product | ||||||||||||
5 | Pepper Deseeder | 19 | Sales | |||||||||||||
6 | Knife Set | 4 | Pepper Deseeder | |||||||||||||
7 | Cutting Board | 7 | 19 | |||||||||||||
8 | Knife Set | |||||||||||||||
9 | Data is stacked into 1 column | 4 | ||||||||||||||
10 | Data is stacked row by row | Cutting Board | ||||||||||||||
11 | Formula in cell J4☛ =ASTACK(B4:C7, H3, H4) | 7 | ||||||||||||||
12 | ||||||||||||||||
13 | ||||||||||||||||
14 | ||||||||||||||||
15 | Original Data | Stack_Into: | 4 | Result | ||||||||||||
16 | Product | Sales | By_Col: | 1 | Product | Product | Sales | Sales | ||||||||
17 | Pepper Deseeder | 19 | Pepper Deseeder | Pepper Deseeder | 19 | 26 | ||||||||||
18 | Knife Set | 4 | Knife Set | Knife Set | 4 | 28 | ||||||||||
19 | Cutting Board | 7 | Cutting Board | Cutting Board | 7 | 16 | ||||||||||
20 | Product | Sales | ||||||||||||||
21 | Pepper Deseeder | 26 | ||||||||||||||
22 | Knife Set | 28 | ||||||||||||||
23 | Cutting Board | 16 | ||||||||||||||
24 | ||||||||||||||||
25 | Data is unstacked into 4 columns | |||||||||||||||
26 | Data is unstacked column by column | |||||||||||||||
27 | Formula in cell J16☛ =ASTACK(B16:C23, H15, H16) | |||||||||||||||
28 | ||||||||||||||||
29 | ||||||||||||||||
30 | ||||||||||||||||
31 | Original Data | Stack_Into: | 2 | Result | ||||||||||||
32 | Item 1.1 | Item 2.1 | Item 3.1 | Item 4.1 | By_Col: | 1 | Item 1.1 | Item 3.1 | ||||||||
33 | Item 1.2 | Item 2.2 | Item 3.2 | Item 4.2 | Item 1.2 | Item 3.2 | ||||||||||
34 | Item 1.3 | Item 2.3 | Item 3.3 | Item 4.3 | Item 1.3 | Item 3.3 | ||||||||||
35 | Item 1.4 | Item 2.4 | Item 3.4 | Item 4.4 | Item 1.4 | Item 3.4 | ||||||||||
36 | Item 2.1 | Item 4.1 | ||||||||||||||
37 | Data is stacked into 2 columns | Item 2.2 | Item 4.2 | |||||||||||||
38 | Data is stacked column by column | Item 2.3 | Item 4.3 | |||||||||||||
39 | Formula in cell J32☛ =ASTACK(B32:E35, H31, H32) | Item 2.4 | Item 4.4 | |||||||||||||
40 | ||||||||||||||||
41 | ||||||||||||||||
42 | ||||||||||||||||
43 | Original Data | Stack_Into: | 4 | Result | ||||||||||||
44 | Item 1.1 | Item 2.1 | By_Col: | 0 | Item 1.1 | Item 2.1 | Item 3.1 | Item 4.1 | ||||||||
45 | Item 3.1 | Item 4.1 | Item 1.2 | Item 2.2 | Item 3.2 | Item 4.2 | ||||||||||
46 | Item 1.2 | Item 2.2 | Item 1.3 | Item 2.3 | Item 3.3 | Item 4.3 | ||||||||||
47 | Item 3.2 | Item 4.2 | Item 1.4 | Item 2.4 | Item 3.4 | Item 4.4 | ||||||||||
48 | Item 1.3 | Item 2.3 | ||||||||||||||
49 | Item 3.3 | Item 4.3 | ||||||||||||||
50 | Item 1.4 | Item 2.4 | ||||||||||||||
51 | Item 3.4 | Item 4.4 | ||||||||||||||
52 | ||||||||||||||||
53 | Data is unstacked into 4 columns | |||||||||||||||
54 | Data is unstacked row by row | |||||||||||||||
55 | Formula in cell J44☛ =ASTACK(B44:C51, H43, H44) | |||||||||||||||
56 | ||||||||||||||||
ASTACK |
Cell Formulas | ||
---|---|---|
Range | Formula | |
J4:J11 | J4 | =ASTACK(B4:C7, H3, H4) |
B11,B39 | B11 | =AFORMULATEXT(J4) |
J16:M19,J44:M47 | J16 | =ASTACK(B16:C23, H15, H16) |
B27,B55 | B27 | =AFORMULATEXT(J16) |
J32:K39 | J32 | =ASTACK(B32:E35, H31, H32) |
Dynamic array formulas. |
Last edited:
Upvote
0