REPT & SEQUENCE to stack results in column

Georgiboy

Well-known Member
Joined
Nov 7, 2008
Messages
1,446
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

Seem to be having some brain fog this morning and have been pondering the below overnight. If i use REPT with SEQUENCE on one row, i.e. one text value and one number for REPT then i get my expected result. If i extend this range to two text cells and two number cells then i only get one of each value. I suppose i am not simply looking for the solution but interested to know why it only gives me one result per row - what is Excels logic:

Lambda-map examples.xlsx
ABCDEFG
1Two versions of a formula working in one row
2Scania5ScaniaScania
3Volvo3ScaniaScania
4ScaniaScania
5ScaniaScania
6ScaniaScania
7
8Same Formula with both rows
9Scania5ScaniaScania
10Volvo3VolvoVolvo
11
12
13
14
15Expected result
16Scania5ScaniaScania
17Volvo3ScaniaScania
18ScaniaScania
19ScaniaScania
20ScaniaScania
21VolvoVolvo
22VolvoVolvo
23VolvoVolvo
Sheet5
Cell Formulas
RangeFormula
E2:E6E2=REPT(A2,SEQUENCE(B2,,1,0))
G2:G6G2=A2&T(SEQUENCE(B2))
E9:E10E9=REPT(A9:A10,SEQUENCE(B9:B10,,1,0))
G9:G10G9=A9:A10&T(SEQUENCE(B9:B10))
Dynamic array formulas.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi

=TOCOL(IF(SEQUENCE(,MAX(B2:B10))<=B2:B10,A2:A10,#N/A),3)
 
Upvote 0
SEQUENCE() is not going to work and give different sequences when applied to multiple cells. Instead, it will just output the 1st element in the sequence, hence you'd get the spilled {1;1}. Applied to your formulas this would then just give you one result each.

Is this what you are tyring perhaps:

Question.xlsx
ABCD
1Scania5Scania
2Volvo3Scania
3Scania
4Scania
5Scania
6Volvo
7Volvo
8Volvo
Sheet3
Cell Formulas
RangeFormula
D1:D8D1=XLOOKUP(SEQUENCE(SUM(B1:B2)),SCAN(0,B1:B2,LAMBDA(a,b,a+b)),A1:A2,,1)
Dynamic array formulas.
 
Last edited:
Upvote 0
Thank you both for the solutions, i am actually after a description of why the displayed examples give one result per REPT when looking at more than one row.

I want to get better understanding of the logic behind why Excel does this (not that it is wrong)

Just seems strange that for one row it spills the result but for two rows it contracts to one result per row.
 
Upvote 0
Yeah, like I said, the SEQUENCE() function is not going to be able to handle multiple reference and output multiple sequences. Imagine =SEQUENCE({5,3}), the function should then output what? {1,2,3,4,5,1,2,3}? It's not going to work like that and instead it will output the 1st element in each sequence as a result > {1,1}.
 
Upvote 0
Solution
Thanks - that helps my understanding, does that mean there could be a combination of something like BYROW with SEQUENCE that would run the SEQUENCE once per row and then stack the results calculated with REPT?

Sorr if the questions seem strange - i have spent the last 15 years writing code and now want to learn Excel 365 formula
 
Upvote 0
Well, yeah, one option is what I've shown as a solution using SCAN(). This is a LAMBDA helper (just like BYROW() is) and would create a running summation of the values in your column B:B:

Question.xlsx
ABC
1Scania55
2Volvo38
Sheet3
Cell Formulas
RangeFormula
C1:C2C1=SCAN(0,B1:B2,LAMBDA(a,b,a+b))
Dynamic array formulas.


Now, you would just need a single SEQUENCE() which is the length of summation of column B:B, which when applied to XLOOKUP we can tell this function to lookup the exact are next larger value and return the values from column A:A. For example, the value 7 is not found as an exact value, but the next larger value is 8. We then return 'Volvo'.

I hope that made sense :S
 
Upvote 0
If you really want to use SEQUENCE() more than once, you would need to stack the different results in an iterative way. One option is REDUCE(), another LAMBDA helper function:

Question.xlsx
ABCD
1Scania5Scania
2Volvo3Scania
3Scania
4Scania
5Scania
6Volvo
7Volvo
8Volvo
Sheet3
Cell Formulas
RangeFormula
D1:D8D1=DROP(REDUCE(0,ROW(A1:A2),LAMBDA(x,y,VSTACK(x,INDEX(A:A,y)&T(SEQUENCE(INDEX(B:B,y)))))),1)
Dynamic array formulas.
 
Upvote 0
Many thanks to both of you, you have helped me to understand why Excel is not doing what i tell it to ;)
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,985
Members
449,201
Latest member
Lunzwe73

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