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
26
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:
Hi @djclements,
Sorry, I just noticed an issue with the formula.

The source data has a leading zero in the period column but the output has dropped the leading zero.
My apologies, I have probably given you a bum steer because my example above also didn't include the leading zero !! 🤦‍♂️ 🫣
I haven't been able to modify it to retain the leading zero.
Could you pls assist ?
 
Upvote 0
The source data has a leading zero in the period column, but the output has dropped the leading zero...

Try using the TEXT function on the period array, e.g. TEXT(period,"00")
Excel Formula:
=LET(
   Val_Repeat, 12,
   x, SEQUENCE(,ROWS(Tbl_Allo)),
   y, SEQUENCE(Val_Repeat,,0),
   a, CHOOSEROWS(Tbl_Allo,TOCOL(IF({1},x,y))),
   SORT(HSTACK(DROP(a,,-1),TEXT(TAKE(a,,-1)+TOCOL(IF(x,y)),"00")),5)
)
 
Upvote 0
Try using the TEXT function on the period array, e.g. TEXT(period,"00")
Excel Formula:
=LET(
   Val_Repeat, 12,
   x, SEQUENCE(,ROWS(Tbl_Allo)),
   y, SEQUENCE(Val_Repeat,,0),
   a, CHOOSEROWS(Tbl_Allo,TOCOL(IF({1},x,y))),
   SORT(HSTACK(DROP(a,,-1),TEXT(TAKE(a,,-1)+TOCOL(IF(x,y)),"00")),5)
)

Thanks. Not sure what happened but when I opened the file again, to make the change you provided above, it had updated with the leading zeros.
Calculation has always been automatic so I'm unsure why it didn't update after I introduced the leading zeros in the source data, unless it took longer to refresh the resulting near half a million records.
 
Upvote 0
Thanks. Not sure what happened but when I opened the file again, to make the change you provided above, it had updated with the leading zeros.
Calculation has always been automatic so I'm unsure why it didn't update after I introduced the leading zeros in the source data, unless it took longer to refresh the resulting near half a million records.

Not sure what you mean either. By the way, if the Period column in your source table (Tbl_Allo) is just filled with "01" for the first period, you can improve performance by dropping this column and utilizing the y sequence instead:
Excel Formula:
=LET(
   Val_Repeat, 12,
   x, SEQUENCE(,ROWS(Tbl_Allo)),
   y, TEXT(SEQUENCE(Val_Repeat),"00"),
   SORT(HSTACK(CHOOSEROWS(DROP(Tbl_Allo,,-1),TOCOL(IFNA(x,y))),TOCOL(IF(x,y))),5)
)

That way, you won't be lifting/broadcasting 2 additional calculations over half a million records.
 
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