Array with repeating text

153 views Asked by At

I am trying to create an array where certain text values are repeated a certain number of times.

For example, the text in row 18 would repeat n number of times where n is in row 19.

excel table

Ive tried several things like let and sequence with no luck.

=LET(in,I18,rep,I19,s,SEQUENCE(ROWS(in)*rep,1,0),INDEX(in,QUOTIENT(E6s,rep)+1))

=TOCOL(CHOOSECOLS(I18,SEQUENCE(I19,1,1,0)))

These both repeat one cell but the correct number of times but I need to add in the other columns.

4

There are 4 answers

0
Tom Sharpe On

Here's one way using Reduce:

=LET(names,I18:R18,
rpts,I19:R19,
REDUCE("Array",SEQUENCE(COLUMNS(names)),
 LAMBDA(a,c,IF(INDEX(rpts,c)=0,a,VSTACK(a,IF(SEQUENCE(INDEX(rpts,c)),INDEX(names,c)))))))

enter image description here

0
Mayukh Bhattacharya On

Here is one way without using LAMBDA() helper:

enter image description here

=TOCOL(IFS(SEQUENCE(MAX(A2:J2))<=A2:J2,A1:J1),2,1)

And here is using LAMBDA() helper MAKEARRAY() version:

=LET(
     α, A1:J1,
     φ, A2:J2,
     TOCOL(MAKEARRAY(COLUMNS(α),MAX(φ),LAMBDA(δ,ε,
     IF(ε<=INDEX(φ,δ),INDEX(α,δ),p))),2))

0
VBasic2008 On

Repeat Columns a Given Number of Times

  • The following is based on Mayukh Bhattacharya's answer to "How to convert a column of age counts into a set useful for statistics?" which covers repeating a row. (What a coincidence: I was just studying it.)

In A17 (Basic):

=LET(data,A1:H3,repeat_rows,{1;3},count_row,2,get_cols,0,
    d,FILTER(data,CHOOSEROWS(data,count_row)>0),
    sr,CHOOSEROWS(d,repeat_rows),
    slr,CHOOSEROWS(d,count_row),
    sl,SCAN(0,slr,LAMBDA(sc,c,sc+c)),
    dl,SEQUENCE(SUM(slr)),
    si,XMATCH(dl,sl,1),
    drs,CHOOSECOLS(sr,si),
    dr,IF(get_cols,TRANSPOSE(drs),drs),
    dr)

In A6 (Transposed): replace get_cols,0, with get_cols,1,)

In D6 (The Requirement): additionally replace A1:H3 with A1:H2 and {1;3} with {1} or 1.

enter image description here

0
user22566114 On

Another alternative with LAMBDA, EXPAND and FILTER.

=LET(z,DROP(REDUCE("",SEQUENCE(COLUMNS(A1:C1)),LAMBDA(u,v,VSTACK(u,IFERROR(IFNA(EXPAND(INDEX(A1:C1,,v),INDEX(A2:C2,,v)),INDEX(A1:C1,,v)),{""})))),1),FILTER(z,LEN(z)>0))

Array with repeating text