Home > Net >  How to use a Lambda function with Reduce to repeat row N numbre f time in google sheets
How to use a Lambda function with Reduce to repeat row N numbre f time in google sheets

Time:01-31

Hello I've tried using text manipulation to achieve the results, and while it works - I don't think it's an efficient way to do it and there is limitations with how many times it can be done.

I was trying to figure out how to get it done with reduce but it having hard time to figure it out.

This is the current table

Unique ID Some other Info How many times to repeat
123 Some Info 2
456 Some Info 3

The result would be

Unique ID
123
123
456
456
456

Thank you.

CodePudding user response:

Here's one way to do this:

=ArrayFormula(REDUCE("Unique ID",SEQUENCE(COUNTA(A2:A)),LAMBDA(a,c,{a;IF(SEQUENCE(INDEX(C2:C,c)),INDEX(A2:A,c))})))

CodePudding user response:

A different approach could be-

=QUERY(FLATTEN(INDEX(SPLIT(REPT(A2:A3&"|",C2:C3),"|"))),"where Col1 is not null")

enter image description here

  • Related