Hello,
This question is related to my previous question below :
I took Stephen's amazing solution and spiced it up to make my LAMBDA more feature-rich, and it works really well (below) :
So now in addition to just "counts" and "break", the "start" and "step" can also be specified along with a "sort" option which works with the standard SORT with "1" and "-1" as arguments. Also now the function takes a vertical input as well, such as {3;2;5}, and the result is vertical spill in a single column. And this all works really well, and the output is obviously linear.
But then I thought to spice up this formula even more and add a "stack" feature as well (where "stack" can be turned on/off) in order to output the multiple counts as multiple columns (or rows in the case of vertical input). This, of course, requires that the "d" variable be taken out of TOROW. But I was not able to get the sorting to work . I tried both 1) to play with SORT parameters and/or 2) to play with the SEQUENCE components of "d" to get the sorting to work for stacked output, but so far I've been unsuccessful . Here is the incomplete formula for the stacked version (I haven't coded the actual stacking mechanism yet):
I thought that the most reasonable sort for stack output would be to sort all columns independently, so the question is what's the best way to do this kind of sorting? I have also included some examples in the XL2BB below.
Thanks for any input
This question is related to my previous question below :
How to generate the specified sequence of numbers based on incrementing portions of the sequence
Hello, Here is a rather complex sequence question 😀 Suppose I have the following partial LET function: =LET( b, {2,1,3,4,2}, c, 12, operation ) The numbers in b indicate the count of numbers in each piece of the final sequence. The first piece starts with 1, and each piece after the...
www.mrexcel.com
I took Stephen's amazing solution and spiced it up to make my LAMBDA more feature-rich, and it works really well (below) :
Excel Formula:
=LET(counts,{5,3,2,4},break,3,start,4,step,-2,sort,1,
b,TOROW(counts),
c,break,
g,IF(ISOMITTED(step),1,step),
m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))),
d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1),
i,d+(IF(ISOMITTED(start),0,start-1)),
f,IF(sort,SORT(i,,sort,1),i),
IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f))
)
So now in addition to just "counts" and "break", the "start" and "step" can also be specified along with a "sort" option which works with the standard SORT with "1" and "-1" as arguments. Also now the function takes a vertical input as well, such as {3;2;5}, and the result is vertical spill in a single column. And this all works really well, and the output is obviously linear.
But then I thought to spice up this formula even more and add a "stack" feature as well (where "stack" can be turned on/off) in order to output the multiple counts as multiple columns (or rows in the case of vertical input). This, of course, requires that the "d" variable be taken out of TOROW. But I was not able to get the sorting to work . I tried both 1) to play with SORT parameters and/or 2) to play with the SEQUENCE components of "d" to get the sorting to work for stacked output, but so far I've been unsuccessful . Here is the incomplete formula for the stacked version (I haven't coded the actual stacking mechanism yet):
Excel Formula:
=LET(counts,{5,3,2,4},break,3,start,4,step,-2,sort,,
b,TOROW(counts),
c,break,
g,IF(ISOMITTED(step),1,step),
m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))),
d,IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),
i,d+(IF(ISOMITTED(start),0,start-1)),
f,IFERROR(IF(sort,SORT(i,,sort,1),i),""),
IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f))
)
I thought that the most reasonable sort for stack output would be to sort all columns independently, so the question is what's the best way to do this kind of sorting? I have also included some examples in the XL2BB below.
Thanks for any input
post.xlsx | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | |||
1 | ||||||||||||||||||||||
2 | sort: omitted | 4 | 2 | 0 | -2 | -4 | 7 | 5 | 3 | 10 | 8 | 13 | 11 | 9 | 7 | |||||||
3 | sort: 1 | -4 | -2 | 0 | 2 | 3 | 4 | 5 | 7 | 7 | 8 | 9 | 10 | 11 | 13 | |||||||
4 | sort: -1 | 13 | 11 | 10 | 9 | 8 | 7 | 7 | 5 | 4 | 3 | 2 | 0 | -2 | -4 | |||||||
5 | ||||||||||||||||||||||
6 | sort: | omitted | sort: | 1 | (intended output) | sort: | -1 | (intended output) | ||||||||||||||
7 | 4 | 7 | 10 | 13 | -4 | 3 | 8 | 7 | 4 | 7 | 10 | 13 | ||||||||||
8 | 2 | 5 | 8 | 11 | -2 | 5 | 10 | 9 | 2 | 5 | 8 | 11 | ||||||||||
9 | 0 | 3 | 9 | 0 | 7 | 11 | 0 | 3 | 9 | |||||||||||||
10 | -2 | 7 | 2 | 13 | -2 | 7 | ||||||||||||||||
11 | -4 | 4 | -4 | |||||||||||||||||||
12 | ||||||||||||||||||||||
13 | ||||||||||||||||||||||
14 | sort: omitted | sort: 1 | sort: -1 | sort: | omitted | |||||||||||||||||
15 | 4 | -4 | 13 | 4 | 2 | 0 | -2 | -4 | ||||||||||||||
16 | 2 | -2 | 11 | 7 | 5 | 3 | ||||||||||||||||
17 | 0 | 0 | 10 | 10 | 8 | |||||||||||||||||
18 | -2 | 2 | 9 | 13 | 11 | 9 | 7 | |||||||||||||||
19 | -4 | 3 | 8 | |||||||||||||||||||
20 | 7 | 4 | 7 | sort: | 1 | (intended output) | ||||||||||||||||
21 | 5 | 5 | 7 | -4 | -2 | 0 | 2 | 4 | ||||||||||||||
22 | 3 | 7 | 5 | 3 | 5 | 7 | ||||||||||||||||
23 | 10 | 7 | 4 | 8 | 10 | |||||||||||||||||
24 | 8 | 8 | 3 | 7 | 9 | 11 | 13 | |||||||||||||||
25 | 13 | 9 | 2 | |||||||||||||||||||
26 | 11 | 10 | 0 | sort: | -1 | (intended output) | ||||||||||||||||
27 | 9 | 11 | -2 | 4 | 2 | 0 | -2 | -4 | ||||||||||||||
28 | 7 | 13 | -4 | 7 | 5 | 3 | ||||||||||||||||
29 | 10 | 8 | ||||||||||||||||||||
30 | 13 | 11 | 9 | 7 | ||||||||||||||||||
31 | ||||||||||||||||||||||
32 | ||||||||||||||||||||||
33 | sort: omitted | -5 | -3.75 | -1.98 | -0.21 | 1.56 | -2.5 | -0.73 | 1.04 | -1.25 | 0.52 | 2.29 | 4.06 | 5.83 | 7.6 | 0 | 1.77 | |||||
34 | sort: 1 | -5 | -3.75 | -2.5 | -1.98 | -1.25 | -0.73 | -0.21 | 0 | 0.52 | 1.04 | 1.56 | 1.77 | 2.29 | 4.06 | 5.83 | 7.6 | |||||
35 | sort: -1 | 7.6 | 5.83 | 4.06 | 2.29 | 1.77 | 1.56 | 1.04 | 0.52 | 0 | -0.21 | -0.73 | -1.25 | -1.98 | -2.5 | -3.75 | -5 | |||||
36 | ||||||||||||||||||||||
37 | sort: | omitted | sort: | 1 | (intended output) | sort: | -1 | (intended output) | ||||||||||||||
38 | -5 | -3.75 | -2.5 | -1.25 | 0 | -5 | -3.75 | -2.5 | -1.25 | 0 | -5 | 1.56 | 1.04 | 7.6 | 1.77 | |||||||
39 | -1.98 | -0.73 | 0.52 | 1.77 | -1.98 | -0.73 | 0.52 | 1.77 | -0.21 | -0.73 | 5.83 | 0 | ||||||||||
40 | -0.21 | 1.04 | 2.29 | -0.21 | 1.04 | 2.29 | -1.98 | -2.5 | 4.06 | |||||||||||||
41 | 1.56 | 4.06 | 1.56 | 4.06 | -3.75 | 2.29 | ||||||||||||||||
42 | 5.83 | 5.83 | 0.52 | |||||||||||||||||||
43 | 7.6 | 7.6 | -1.25 | |||||||||||||||||||
44 | ||||||||||||||||||||||
45 | ||||||||||||||||||||||
46 | sort: omitted | sort: 1 | sort: -1 | sort: | omitted | |||||||||||||||||
47 | -5 | -5 | 7.6 | -5 | ||||||||||||||||||
48 | -3.75 | -3.75 | 5.83 | -3.75 | -1.98 | -0.21 | 1.56 | |||||||||||||||
49 | -1.98 | -2.5 | 4.06 | -2.5 | -0.73 | 1.04 | ||||||||||||||||
50 | -0.21 | -1.98 | 2.29 | -1.25 | 0.52 | 2.29 | 4.06 | 5.83 | 7.6 | |||||||||||||
51 | 1.56 | -1.25 | 1.77 | 0 | 1.77 | |||||||||||||||||
52 | -2.5 | -0.73 | 1.56 | |||||||||||||||||||
53 | -0.73 | -0.21 | 1.04 | sort: | 1 | (intended output) | ||||||||||||||||
54 | 1.04 | 0 | 0.52 | -5 | ||||||||||||||||||
55 | -1.25 | 0.52 | 0 | -3.75 | -1.98 | -0.21 | 1.56 | |||||||||||||||
56 | 0.52 | 1.04 | -0.21 | -2.5 | -0.73 | 1.04 | ||||||||||||||||
57 | 2.29 | 1.56 | -0.73 | -1.25 | 0.52 | 2.29 | 4.06 | 5.83 | 7.6 | |||||||||||||
58 | 4.06 | 1.77 | -1.25 | 0 | 1.77 | |||||||||||||||||
59 | 5.83 | 2.29 | -1.98 | |||||||||||||||||||
60 | 7.6 | 4.06 | -2.5 | sort: | -1 | (intended output) | ||||||||||||||||
61 | 0 | 5.83 | -3.75 | -5 | ||||||||||||||||||
62 | 1.77 | 7.6 | -5 | 1.56 | -0.21 | -1.98 | -3.75 | |||||||||||||||
63 | 1.04 | -0.73 | -2.5 | |||||||||||||||||||
64 | 7.6 | 5.83 | 4.06 | 2.29 | 0.52 | -1.25 | ||||||||||||||||
65 | 1.77 | 0 | ||||||||||||||||||||
66 | ||||||||||||||||||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
C2:P2 | C2 | =LET(counts,{5,3,2,4},break,3,start,4,step,-2,sort,, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C3:P3 | C3 | =LET(counts,{5,3,2,4},break,3,start,4,step,-2,sort,1, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C4:P4 | C4 | =LET(counts,{5,3,2,4},break,3,start,4,step,-2,sort,-1, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C7:F11,M7:P11 | C7 | =LET(counts,{5,3,2,4},break,3,start,4,step,-2,sort,, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)), i,d+(IF(ISOMITTED(start),0,start-1)), f,IFERROR(IF(sort,SORT(i,,sort,1),i),""), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C15:C28 | C15 | =LET(counts,{5;3;2;4},break,3,start,4,step,-2,sort,, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
D15:D28 | D15 | =LET(counts,{5;3;2;4},break,3,start,4,step,-2,sort,1, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
E15:E28 | E15 | =LET(counts,{5;3;2;4},break,3,start,4,step,-2,sort,-1, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
G15:K18 | G15 | =LET(counts,{5;3;2;4},break,3,start,4,step,-2,sort,, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)), i,d+(IF(ISOMITTED(start),0,start-1)), f,IFERROR(IF(sort,SORT(i,,sort,1),i),""), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C33:R33 | C33 | =LET(counts,{1,4,3,6,2},break,1.25,start,-5,step,1.77,sort,, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C34:R34 | C34 | =LET(counts,{1,4,3,6,2},break,1.25,start,-5,step,1.77,sort,1, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C35:R35 | C35 | =LET(counts,{1,4,3,6,2},break,1.25,start,-5,step,1.77,sort,-1, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C38:G43 | C38 | =LET(counts,{1,4,3,6,2},break,1.25,start,-5,step,1.77,sort,, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)), i,d+(IF(ISOMITTED(start),0,start-1)), f,IFERROR(IF(sort,SORT(i,,sort,1),i),""), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
C47:C62 | C47 | =LET(counts,{1;4;3;6;2},break,1.25,start,-5,step,1.77,sort,, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
D47:D62 | D47 | =LET(counts,{1;4;3;6;2},break,1.25,start,-5,step,1.77,sort,1, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
E47:E62 | E47 | =LET(counts,{1;4;3;6;2},break,1.25,start,-5,step,1.77,sort,-1, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,TOROW(IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)),2,1), i,d+(IF(ISOMITTED(start),0,start-1)), f,IF(sort,SORT(i,,sort,1),i), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
G47:L51 | G47 | =LET(counts,{1;4;3;6;2},break,1.25,start,-5,step,1.77,sort,, b,TOROW(counts), c,break, g,IF(ISOMITTED(step),1,step), m,SEQUENCE(MAX(b),,,ABS(IF(g,g,1))), d,IFS(m<=(b*ABS(IF(g,g,1))),IF(g<=0,SEQUENCE(MAX(b),,,g),m)+SEQUENCE(,COUNT(b),0,c)), i,d+(IF(ISOMITTED(start),0,start-1)), f,IFERROR(IF(sort,SORT(i,,sort,1),i),""), IF(COLUMNS(counts)>=ROWS(counts),f,TRANSPOSE(f)) ) |
Dynamic array formulas. |