Search code examples
google-sheets-formula

Repat the rows n times when column data is present


Make a copy of sheet here

I have an input as shown here enter image description here

The expected output is enter image description here

The A to G column data needs to be repeated in the rows n times where n is the count of items present in the range H to Q

For example the 5th row A4 B4 H6 D4 E4 F4 G4 is repeated 5 times since H5 to Q5 column has 5 entries for the 5th row

I have tried with =ArrayFormula(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY({A1:G10,TRANSPOSE(SPLIT(REPT(CONCATENATE(H1:Q1&","),COUNTA(H1:Q1)),","))},"Select * ")),","))))


Solution

  • You may try:

    =index(let(Σ,{"","","","","","",""},Ξ,H2:index(Q:Q,match(2,1/(byrow(A1:G14,lambda(Σ,textjoin("",1,Σ)))<>""))),Δ,byrow(Ξ,lambda(Σ,max(1,counta(Σ)))),Γ,byrow(Ξ,lambda(Σ,if(counta(Σ)=0,"🐠",Σ))),
              {query(reduce(Σ,sequence(counta(A2:A14)),lambda(a,c,{a;if(sequence(index(Δ,c)),index(A2:G14,c))})),"offset 1"),
              substitute(tocol(Γ,1),"🐠","")}))
    

    OR

    =index(let(Σ,match(2,1/(byrow(A1:G14,lambda(Σ,textjoin("",1,Σ)))<>"")),
              {iferror(split(tocol(map(byrow(A2:index(G:G,Σ),lambda(Σ,textjoin("|",1,Σ))),byrow(H2:index(Q:Q,Σ),lambda(Σ,max(1,counta(Σ)))),lambda(a,b,wraprows(a,b,a))),1),"|")),
              substitute(tocol(byrow(H2:index(Q:Q,Σ),lambda(Σ,if(counta(Σ)=0,"🐠",Σ))),1),"🐠","")}))
    

    enter image description here