Replicate data from a table n number of times and increment one of the values for each iteration

gavcol

New Member
Joined
Dec 22, 2016
Messages
24
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi,

I have a data table "Tbl_Allo" with a couple of thousand records but the below table is a good example subset of the data.
InOutRefRateYearPeriod
AAAA11A0.0001202601
BBB#1B0.0467202601
CCC#1C0.1727202601
DDDD11D0.1722202601
AAAA11A0.5314053202701
BBB#1B0.0424033202701
CCCC11C0.0157139202701
DDDD11D0.0000541202701

What I need to achieve, preferably with a formula but happy to use power query (but not VB), is a way to recreate the table a specific n number of times (n = a variable named value "Val_Repeat" ), however I need the Period value to increment at each replication up to a maximum of 12.

I have already created a horrifically long formula (takes up nearly the whole screen) with a mixture of LET, FILTER, VSTACK and HSTACK functions but I would like a more efficient way of producing the replicated data.
Would prefer to do it in a single formula. Note, because the data contains the # it caused a problem with earlier versions of the formula that used the sequence function.

Hoping someone can suggest a way to do this with a single formula and output to a single spill dataset.
Thank you
 
Last edited:
So that we are sure what you are after, could you post the expected results for if "Val_Repeat" was, say, 3?
 
Upvote 0
Not entirely clear what the expected outcome is, but here's a few examples to get you started...

Basic repeat array (vertically):
Excel Formula:
=LET(
   Val_Repeat, 6,
   CHOOSEROWS(Tbl_Allo,TOCOL(IF(SEQUENCE(Val_Repeat),SEQUENCE(,ROWS(Tbl_Allo)))))
)

Repeat array, with appended instance_num column:
Excel Formula:
=LET(
   Val_Repeat, 6,
   x, SEQUENCE(,ROWS(Tbl_Allo)),
   y, SEQUENCE(Val_Repeat),
   HSTACK(CHOOSEROWS(Tbl_Allo,TOCOL(IF(y,x))),TOCOL(IF(x,y)))
)

Repeat array, then add the instance_num to the existing Period column (last column):
Excel Formula:
=LET(
   Val_Repeat, 6,
   x, SEQUENCE(,ROWS(Tbl_Allo)),
   y, SEQUENCE(Val_Repeat),
   a, CHOOSEROWS(Tbl_Allo,TOCOL(IF(y,x))),
   HSTACK(DROP(a,,-1),TAKE(a,,-1)+TOCOL(IF(x,y)))
)

Repeat array, then add the instance_num (starting from 0) to the Period column:
Excel Formula:
=LET(
   Val_Repeat, 6,
   x, SEQUENCE(,ROWS(Tbl_Allo)),
   y, SEQUENCE(Val_Repeat,,0),
   a, CHOOSEROWS(Tbl_Allo,TOCOL(IF({1},x,y))),
   HSTACK(DROP(a,,-1),TAKE(a,,-1)+TOCOL(IF(x,y)))
)

There are a multitude of variations this method can take, depending on your desired output. If none of these examples meet your needs, please provide some sample results, as mentioned by Peter.
 
Upvote 0
Solution
Repeat array, then add the instance_num (starting from 0) to the Period column:
Excel Formula:
=LET(
   Val_Repeat, 6,
   x, SEQUENCE(,ROWS(Tbl_Allo)),
   y, SEQUENCE(Val_Repeat,,0),
   a, CHOOSEROWS(Tbl_Allo,TOCOL(IF({1},x,y))),
   HSTACK(DROP(a,,-1),TAKE(a,,-1)+TOCOL(IF(x,y)))
)

There are a multitude of variations this method can take, depending on your desired output. If none of these examples meet your needs, please provide some sample results, as mentioned by Peter.
Hello,

Just out of curiosity, what does this part means in your last formula?
Excel Formula:
IF({1},x,y)
I struggle to understand when you'd reach y, and also why the brackets ?

Tyvm
 
Upvote 0
@saboh12617

In the 2nd and 3rd examples, y was defined as SEQUENCE(6), returning a vertical vector from 1 to 6. Since the IF function interprets any numeric value other than 0 as TRUE, IF(y,x) was all that was needed to broadcast (repeat) the horizontal x vector across all 6 rows of the y vector.

In the last example, however, y was defined as SEQUENCE(6,,0), returning a vertical vector from 0 to 5. Since 0 is interpreted as FALSE, the same IF(y,x) construct will not work correctly. Instead, IF({1},x,y) is used to successfully broadcast the horizontal x vector across each row of the y vector. Whenever the logical_test argument of IF receives an array object (TYPE 64), all three arguments are resized to be the same length/width as the argument(s) with the greatest number of rows and columns.
 
Upvote 0
Ohhh that's a very clever way to duplicate an array indeed!
Do you have a link where I could learn more about the interactions between Excel Formulas and types casting/inferences – Especially for arrays? It is the first time I see it explained in those technical terms, I think it can help me understanding and working with arrays better.

Thanks for your time sir, have a good day.
 
Upvote 0
So that we are sure what you are after, could you post the expected results for if "Val_Repeat" was, say, 3?

Hi Peter, Thanks for the response.

I may have given a bum steer in the original post. I don't need it by n val_repeat because the source data will already include the first period of data in each year which needs to be replicated to the other 11 periods.

I hope this expected output explains it better.

Replicate dataset by 12 for each year.xlsb
ABCDEFGHIJKLMNO
1Source Data table (period 1 for each year is provided, but need 12 periods replicated for each year which has different rates in period 1 for each year)
2
3Expected Output = Replicated data (x 12 periods for each RepYear)
4InOutRefRateYearPeriodInOutRefRateRepYearPeriod
5AAAA11A0.0000120261AAAA11A0.0000120261Subset #1 replicate by 12 periods for 2026
6BBB#1B0.0000220261BBB#1B0.0000220261
7CCC#1C0.0000320261CCC#1C0.0000320261
8DDDD11D0.0000420261DDDD11D0.0000420261
9AAAA11A0.0000120262AAAA11A0.00520271Subset #2 replicate by 12 periods for 2027
10BBB#1B0.0000220262BBB#1B0.00620271
11CCC#1C0.0000320262CCCC11C0.00720271
12DDDD11D0.0000420262DDDD11D0.00820271
13AAAA11A0.0000120263AAAA11A0.120281Subset #3 replicate by 12 periods for 2028
14BBB#1B0.0000220263BBB#1B0.320281
15CCC#1C0.0000320263CCCC11C0.620281
16DDDD11D0.0000420263DDDD11D0.920281
17AAAA11A0.0000120264
18BBB#1B0.0000220264
19CCC#1C0.0000320264
20DDDD11D0.0000420264
21AAAA11A0.0000120265
22BBB#1B0.0000220265
23CCC#1C0.0000320265
24DDDD11D0.0000420265
25AAAA11A0.0000120266
26BBB#1B0.0000220266
27CCC#1C0.0000320266
28DDDD11D0.0000420266
29AAAA11A0.0000120267
30BBB#1B0.0000220267
31CCC#1C0.0000320267
32DDDD11D0.0000420267
33AAAA11A0.0000120268
34BBB#1B0.0000220268
35CCC#1C0.0000320268
36DDDD11D0.0000420268
37AAAA11A0.0000120269
38BBB#1B0.0000220269
39CCC#1C0.0000320269
40DDDD11D0.0000420269
41AAAA11A0.00001202610
42BBB#1B0.00002202610
43CCC#1C0.00003202610
44DDDD11D0.00004202610
45AAAA11A0.00001202611
46BBB#1B0.00002202611
47CCC#1C0.00003202611
48DDDD11D0.00004202611
49AAAA11A0.00001202612
50BBB#1B0.00002202612
51CCC#1C0.00003202612
52DDDD11D0.00004202612
53AAAA11A0.00520271
54BBB#1B0.00620271
55CCC#1C0.00720271
56DDDD11D0.00820271
57AAAA11A0.00520272
58BBB#1B0.00620272
59CCC#1C0.00720272
60DDDD11D0.00820272
61AAAA11A0.00520273
62BBB#1B0.00620273
63CCC#1C0.00720273
64DDDD11D0.00820273
65AAAA11A0.00520274
66BBB#1B0.00620274
67CCC#1C0.00720274
68DDDD11D0.00820274
69AAAA11A0.00520275
70BBB#1B0.00620275
71CCC#1C0.00720275
72DDDD11D0.00820275
73AAAA11A0.00520276
74BBB#1B0.00620276
75CCC#1C0.00720276
76DDDD11D0.00820276
77AAAA11A0.00520277
78BBB#1B0.00620277
79CCC#1C0.00720277
80DDDD11D0.00820277
81AAAA11A0.00520278
82BBB#1B0.00620278
83CCC#1C0.00720278
84DDDD11D0.00820278
85AAAA11A0.00520279
86BBB#1B0.00620279
87CCC#1C0.00720279
88DDDD11D0.00820279
89AAAA11A0.005202710
90BBB#1B0.006202710
91CCC#1C0.007202710
92DDDD11D0.008202710
93AAAA11A0.005202711
94BBB#1B0.006202711
95CCC#1C0.007202711
96DDDD11D0.008202711
97AAAA11A0.005202712
98BBB#1B0.006202712
99CCC#1C0.007202712
100DDDD11D0.008202712
101AAAA11A0.120281
102BBB#1B0.320281
103CCC#1C0.620281
104DDDD11D0.920281
105AAAA11A0.120282
106BBB#1B0.320282
107CCC#1C0.620282
108DDDD11D0.920282
109AAAA11A0.120283
110BBB#1B0.320283
111CCC#1C0.620283
112DDDD11D0.920283
113AAAA11A0.120284
114BBB#1B0.320284
115CCC#1C0.620284
116DDDD11D0.920284
117AAAA11A0.120285
118BBB#1B0.320285
119CCC#1C0.620285
120DDDD11D0.920285
121AAAA11A0.120286
122BBB#1B0.320286
123CCC#1C0.620286
124DDDD11D0.920286
125AAAA11A0.120287
126BBB#1B0.320287
127CCC#1C0.620287
128DDDD11D0.920287
129AAAA11A0.120288
130BBB#1B0.320288
131CCC#1C0.620288
132DDDD11D0.920288
133AAAA11A0.120289
134BBB#1B0.320289
135CCC#1C0.620289
136DDDD11D0.920289
137AAAA11A0.1202810
138BBB#1B0.3202810
139CCC#1C0.6202810
140DDDD11D0.9202810
141AAAA11A0.1202811
142BBB#1B0.3202811
143CCC#1C0.6202811
144DDDD11D0.9202811
145AAAA11A0.1202812
146BBB#1B0.3202812
147CCC#1C0.6202812
148DDDD11D0.9202812
Source
 
Last edited:
Upvote 0
Hi Peter, Thanks for the response.

I may have given a bum steer in the original post. I don't need it by n val_repeat because the source data will already include the first period of data in each year which needs to be replicated to the other 11 periods.

I hope this expected output explains it better.

Replicate dataset by 12 for each year.xlsb
ABCDEFGHIJKLMNO
1Source Data table (period 1 for each year is provided, but need 12 periods replicated for each year which has different rates in period 1 for each year)
2
3Expected Output = Replicated data (x 12 periods for each RepYear)
4InOutRefRateYearPeriodInOutRefRateRepYearPeriod
5AAAA11A0.0000120261AAAA11A0.0000120261Subset #1 replicate by 12 periods for 2026
6BBB#1B0.0000220261BBB#1B0.0000220261
7CCC#1C0.0000320261CCC#1C0.0000320261
8DDDD11D0.0000420261DDDD11D0.0000420261
9AAAA11A0.0000120262AAAA11A0.00520271Subset #2 replicate by 12 periods for 2027
10BBB#1B0.0000220262BBB#1B0.00620271
11CCC#1C0.0000320262CCCC11C0.00720271
12DDDD11D0.0000420262DDDD11D0.00820271
13AAAA11A0.0000120263AAAA11A0.120281Subset #3 replicate by 12 periods for 2028
14BBB#1B0.0000220263BBB#1B0.320281
15CCC#1C0.0000320263CCCC11C0.620281
16DDDD11D0.0000420263DDDD11D0.920281
17AAAA11A0.0000120264
18BBB#1B0.0000220264
19CCC#1C0.0000320264
20DDDD11D0.0000420264
21AAAA11A0.0000120265
22BBB#1B0.0000220265
23CCC#1C0.0000320265
24DDDD11D0.0000420265
25AAAA11A0.0000120266
26BBB#1B0.0000220266
27CCC#1C0.0000320266
28DDDD11D0.0000420266
29AAAA11A0.0000120267
30BBB#1B0.0000220267
31CCC#1C0.0000320267
32DDDD11D0.0000420267
33AAAA11A0.0000120268
34BBB#1B0.0000220268
35CCC#1C0.0000320268
36DDDD11D0.0000420268
37AAAA11A0.0000120269
38BBB#1B0.0000220269
39CCC#1C0.0000320269
40DDDD11D0.0000420269
41AAAA11A0.00001202610
42BBB#1B0.00002202610
43CCC#1C0.00003202610
44DDDD11D0.00004202610
45AAAA11A0.00001202611
46BBB#1B0.00002202611
47CCC#1C0.00003202611
48DDDD11D0.00004202611
49AAAA11A0.00001202612
50BBB#1B0.00002202612
51CCC#1C0.00003202612
52DDDD11D0.00004202612
53AAAA11A0.00520271
54BBB#1B0.00620271
55CCC#1C0.00720271
56DDDD11D0.00820271
57AAAA11A0.00520272
58BBB#1B0.00620272
59CCC#1C0.00720272
60DDDD11D0.00820272
61AAAA11A0.00520273
62BBB#1B0.00620273
63CCC#1C0.00720273
64DDDD11D0.00820273
65AAAA11A0.00520274
66BBB#1B0.00620274
67CCC#1C0.00720274
68DDDD11D0.00820274
69AAAA11A0.00520275
70BBB#1B0.00620275
71CCC#1C0.00720275
72DDDD11D0.00820275
73AAAA11A0.00520276
74BBB#1B0.00620276
75CCC#1C0.00720276
76DDDD11D0.00820276
77AAAA11A0.00520277
78BBB#1B0.00620277
79CCC#1C0.00720277
80DDDD11D0.00820277
81AAAA11A0.00520278
82BBB#1B0.00620278
83CCC#1C0.00720278
84DDDD11D0.00820278
85AAAA11A0.00520279
86BBB#1B0.00620279
87CCC#1C0.00720279
88DDDD11D0.00820279
89AAAA11A0.005202710
90BBB#1B0.006202710
91CCC#1C0.007202710
92DDDD11D0.008202710
93AAAA11A0.005202711
94BBB#1B0.006202711
95CCC#1C0.007202711
96DDDD11D0.008202711
97AAAA11A0.005202712
98BBB#1B0.006202712
99CCC#1C0.007202712
100DDDD11D0.008202712
101AAAA11A0.120281
102BBB#1B0.320281
103CCC#1C0.620281
104DDDD11D0.920281
105AAAA11A0.120282
106BBB#1B0.320282
107CCC#1C0.620282
108DDDD11D0.920282
109AAAA11A0.120283
110BBB#1B0.320283
111CCC#1C0.620283
112DDDD11D0.920283
113AAAA11A0.120284
114BBB#1B0.320284
115CCC#1C0.620284
116DDDD11D0.920284
117AAAA11A0.120285
118BBB#1B0.320285
119CCC#1C0.620285
120DDDD11D0.920285
121AAAA11A0.120286
122BBB#1B0.320286
123CCC#1C0.620286
124DDDD11D0.920286
125AAAA11A0.120287
126BBB#1B0.320287
127CCC#1C0.620287
128DDDD11D0.920287
129AAAA11A0.120288
130BBB#1B0.320288
131CCC#1C0.620288
132DDDD11D0.920288
133AAAA11A0.120289
134BBB#1B0.320289
135CCC#1C0.620289
136DDDD11D0.920289
137AAAA11A0.1202810
138BBB#1B0.3202810
139CCC#1C0.6202810
140DDDD11D0.9202810
141AAAA11A0.1202811
142BBB#1B0.3202811
143CCC#1C0.6202811
144DDDD11D0.9202811
145AAAA11A0.1202812
146BBB#1B0.3202812
147CCC#1C0.6202812
148DDDD11D0.9202812
Source

So the request should have been to replicate the data for each RepYear and Period by 11 and increment the Period by 1 for each replication.
 
Upvote 0
Not entirely clear what the expected outcome is, but here's a few examples to get you started...
There are a multitude of variations this method can take, depending on your desired output. If none of these examples meet your needs, please provide some sample results, as mentioned by Peter.

@djclements - Holy dooley that last one did it perfectly once I changed the Val_Repeat to12 !!!
I don't know why my earlier formula with SEQUENCE had such a problem with the # values and I had played around with TOCOL but I never even thought of using the drop and take functions !!
I am properly amazed at this.
Thank you muchly. This is exactly what I needed !!! (It's a different sort sequence to my example above but that doesn't matter at all. The production of the records was all that was required)
1740830062558.png
 
Last edited:
Upvote 0
and just for some icing, a little update to sort..............
(though I adjusted the example rates a bit to ensure the sort didn't re sort by their values)
Excel Formula:
=SORT(LET(
   Val_Repeat, 12,
   x, SEQUENCE(,ROWS(Tbl_Allo)),
   y, SEQUENCE(Val_Repeat,,0),
   a, CHOOSEROWS(Tbl_Allo,TOCOL(IF({1},x,y))),
   HSTACK(DROP(a,,-1),TAKE(a,,-1)+TOCOL(IF(x,y)))
),5)

.............the output then results in something I can give to end users in a way they'll understand the data

Replicate dataset by 12 for each year.xlsb
ABCDEFGHIJKLMNOP
1InOutRefRateYearPeriodSource Data table (period 1 for each year is provided, but need 12 periods replicated for each year which has different rates in period 1 for each year)
2AAAA11A0.0000920261
3BBB#1B0.0000820261
4CCC#1C0.0000720261InOutRefRateRepYearPeriod
5DDDD11D0.0000620261AAAA11A0.0000920261Subset #1 replicate by 12 periods for 2026
6AAAA11A0.0000920262BBB#1B0.0000820261
7BBB#1B0.0000820262CCC#1C0.0000720261
8CCC#1C0.0000720262DDDD11D0.0000620261
9DDDD11D0.0000620262AAAA11A0.00820271Subset #2 replicate by 12 periods for 2027
10AAAA11A0.0000920263BBB#1B0.00620271
11BBB#1B0.0000820263CCCC11C0.00720271
12CCC#1C0.0000720263DDDD11D0.00520271
13DDDD11D0.0000620263AAAA11A0.120281Subset #3 replicate by 12 periods for 2028
14AAAA11A0.0000920264BBB#1B0.320281
15BBB#1B0.0000820264CCCC11C0.620281
16CCC#1C0.0000720264DDDD11D0.920281
17DDDD11D0.0000620264
18AAAA11A0.0000920265
19BBB#1B0.0000820265
20CCC#1C0.0000720265
21DDDD11D0.0000620265
22AAAA11A0.0000920266
23BBB#1B0.0000820266
24CCC#1C0.0000720266
25DDDD11D0.0000620266
26AAAA11A0.0000920267
27BBB#1B0.0000820267
28CCC#1C0.0000720267
29DDDD11D0.0000620267
30AAAA11A0.0000920268
31BBB#1B0.0000820268
32CCC#1C0.0000720268
33DDDD11D0.0000620268
34AAAA11A0.0000920269
35BBB#1B0.0000820269
36CCC#1C0.0000720269
37DDDD11D0.0000620269
38AAAA11A0.00009202610
39BBB#1B0.00008202610
40CCC#1C0.00007202610
41DDDD11D0.00006202610
42AAAA11A0.00009202611
43BBB#1B0.00008202611
44CCC#1C0.00007202611
45DDDD11D0.00006202611
46AAAA11A0.00009202612
47BBB#1B0.00008202612
48CCC#1C0.00007202612
49DDDD11D0.00006202612
50AAAA11A0.00820271
51BBB#1B0.00620271
52CCCC11C0.00720271
53DDDD11D0.00520271
54AAAA11A0.00820272
55BBB#1B0.00620272
56CCCC11C0.00720272
57DDDD11D0.00520272
58AAAA11A0.00820273
59BBB#1B0.00620273
60CCCC11C0.00720273
61DDDD11D0.00520273
62AAAA11A0.00820274
63BBB#1B0.00620274
64CCCC11C0.00720274
65DDDD11D0.00520274
66AAAA11A0.00820275
67BBB#1B0.00620275
68CCCC11C0.00720275
69DDDD11D0.00520275
70AAAA11A0.00820276
71BBB#1B0.00620276
72CCCC11C0.00720276
73DDDD11D0.00520276
74AAAA11A0.00820277
75BBB#1B0.00620277
76CCCC11C0.00720277
77DDDD11D0.00520277
78AAAA11A0.00820278
79BBB#1B0.00620278
80CCCC11C0.00720278
81DDDD11D0.00520278
82AAAA11A0.00820279
83BBB#1B0.00620279
84CCCC11C0.00720279
85DDDD11D0.00520279
86AAAA11A0.008202710
87BBB#1B0.006202710
88CCCC11C0.007202710
89DDDD11D0.005202710
90AAAA11A0.008202711
91BBB#1B0.006202711
92CCCC11C0.007202711
93DDDD11D0.005202711
94AAAA11A0.008202712
95BBB#1B0.006202712
96CCCC11C0.007202712
97DDDD11D0.005202712
98AAAA11A0.120281
99BBB#1B0.320281
100CCCC11C0.620281
101DDDD11D0.920281
102AAAA11A0.120282
103BBB#1B0.320282
104CCCC11C0.620282
105DDDD11D0.920282
106AAAA11A0.120283
107BBB#1B0.320283
108CCCC11C0.620283
109DDDD11D0.920283
110AAAA11A0.120284
111BBB#1B0.320284
112CCCC11C0.620284
113DDDD11D0.920284
114AAAA11A0.120285
115BBB#1B0.320285
116CCCC11C0.620285
117DDDD11D0.920285
118AAAA11A0.120286
119BBB#1B0.320286
120CCCC11C0.620286
121DDDD11D0.920286
122AAAA11A0.120287
123BBB#1B0.320287
124CCCC11C0.620287
125DDDD11D0.920287
126AAAA11A0.120288
127BBB#1B0.320288
128CCCC11C0.620288
129DDDD11D0.920288
130AAAA11A0.120289
131BBB#1B0.320289
132CCCC11C0.620289
133DDDD11D0.920289
134AAAA11A0.1202810
135BBB#1B0.3202810
136CCCC11C0.6202810
137DDDD11D0.9202810
138AAAA11A0.1202811
139BBB#1B0.3202811
140CCCC11C0.6202811
141DDDD11D0.9202811
142AAAA11A0.1202812
143BBB#1B0.3202812
144CCCC11C0.6202812
145DDDD11D0.9202812
Outcome
Cell Formulas
RangeFormula
A2:F145A2=SORT(LET( Val_Repeat, 12, x, SEQUENCE(,ROWS(Tbl_Allo)), y, SEQUENCE(Val_Repeat,,0), a, CHOOSEROWS(Tbl_Allo,TOCOL(IF({1},x,y))), HSTACK(DROP(a,,-1),TAKE(a,,-1)+TOCOL(IF(x,y))) ),5)
Dynamic array formulas.
 
Upvote 0

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