Intro
- I wrote an answer to Expand records for each month between two dates. A part of my solution was to stack integer sequences from a column of integers. There were only 4 integers in the column, so I opted for the 'straightforward'
DROP/REDUCE/VSTACKcombo. Later, when testing my formula with 10k integers (stacks), as you can probably guess, it became unbearable to wait for the result. Is there a way to generate the result more efficiently?
The Task
- I have a list (column) of integers in
A2:A4. For each next integer, I want to generate a sequence of the size of the integer and stack it below the previously generated one.
| Size | Result | |
|---|---|---|
| 2 | 1 | |
| 5 | 2 | |
| 3 | 1 | |
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 1 | ||
| 2 | ||
| 3 |
I'm currently using the following (slow) formula:
=LET(data,A2:A4,DROP(REDUCE("",SEQUENCE(ROWS(data)),LAMBDA(rr,r, VSTACK(rr,SEQUENCE(INDEX(data,r))))),1))You could generate the large dataset with the formula
=RANDARRAY(10000,,1,9,1), then copy/paste values and replaceA2:A4withA2:A10001in your formula.I'm primarily interested in a formula for Excel 365 but solutions for Legacy Excel, Power Query, or VBA might be useful to the community.







=LET(_a, A2:A4, _b, SEQUENCE(, MAX(_a)), TOCOL(IF(_b <= _a, _b, 0/0), 3)))bt I think PQ is better here0/0.=RANDARRAY(10000, , 2, 6, 1)can you try and let me know if its working for you or notRANDARRAYformula.