Repeat multiple columns - google-sheets

How to implement multiple column repetition using formulas? Here is my sheet. For example, I need to repeat the range A1:C5 N-times so that the result is like in the range E1:G25. Thanks for the help.

I will try to simplify below formula but it works-
=ArrayFormula(SPLIT(FLATTEN(SPLIT(REPT(ArrayFormula(TEXTJOIN("#";FALSE;"#"&A1:A5&"#"&B1:B5&"#"&C1:C5));5);"#"));"#";;FALSE))
See your sheet

try:
={OFFSET(A1:C;;;COUNTA(A1:A));
OFFSET(A1:C;;;COUNTA(A1:A));
OFFSET(A1:C;;;COUNTA(A1:A));
OFFSET(A1:C;;;COUNTA(A1:A));
OFFSET(A1:C;;;COUNTA(A1:A))}

Another way, number of reps in D1, number of rows and columns in range to be copied can vary:
=ArrayFormula(vlookup(
mod(quotient(sequence(D1*rows(A1:C5),columns(A1:C5),0),columns(A1:C5)),rows(A1:C5))+1,
{row(A1:C5),A1:C5},
mod(sequence(D1*rows(A1:C5),columns(A1:C5),0),columns(A1:C5))+2))
For your locale:
=ArrayFormula(vlookup(
mod(quotient(sequence(P1*rows(A1:C5);columns(A1:C5);0);columns(A1:C5));rows(A1:C5))+1;
{row(A1:C5)\A1:C5};
mod(sequence(P1*rows(A1:C5);columns(A1:C5);0);columns(A1:C5))+2))

Related

How to change the TextJoin range in google sheet dynamically based on empty cell

I want to join the text but the number of rows differ for each record. If I use the static range data is missing for few records, in below example 22Inch is missing,
Used the below formula. How to dynamically change the range.
=TEXTJOIN(",",TRUE,A3:A8,"")
try:
=TEXTJOIN(",", 1, A3:INDEX(A:A, MIN(IFERROR(1/(1/(ROW(A3:A)*(A3:A="")))))))
Can you test this one out:
=LAMBDA(z,BYROW(z,LAMBDA(a,REGEXREPLACE(TEXTJOIN(",",1,IFNA(FILTER(A2:A,XLOOKUP(ROW(B2:B),z,z,,-1)=a))),"^(.*?)\,",""))))({ROW();BYROW(A3:A,LAMBDA(z,IF((z<>"")*(OFFSET(z,-1,0)=""),ROW(z),)))})
Here's another formula you can try:
=QUERY(INDEX(LAMBDA(ζ,SORT(REGEXREPLACE(ζ,"^,",),COUNTIFS(A1:A,"",ROW(A1:A),"<="&ROW(A1:A)),1,LEN(ζ),))({"";IF({A3:A;""}<>"",,SCAN(,A2:A,LAMBDA(a,c,IF(c="",,a&","&c))))})),"limit "&ROWS(A2:A))

Repeating a value on the basis of count provided in another cell - Google Sheets

I'm trying to write a formula where I can generate a number n number of times where n can be the input provided by the user.
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
REPT($D2&",", $E2), ), ","))))
Ideal output
Here D2 is the value to be repeated and E2 is the number of times.
So instead of manually using this formula after each last repeated value to generate the next set of repeated values, I want to print the values in one go. I'll be really grateful, if anyone could please provide a way around to do the same. Thanks in advance.
Try this
=ARRAY_CONSTRAIN(arrayformula(query(flatten(split(rept("|"&D2:D,E2:E),"|")),"select * where Col1 is not null")),SUM(E2:E),1)
explanation
the core of the formula is
=arrayformula(iferror(split(rept("|"&D2:D,E2:E),"|")))
then, apply flatten with a limitation of rows (ARRAY_CONSTRAIN) equal to the sum of column E, and query only the rows that are not null
Try the below formula:
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
REPT(D2:D&",", E2:E), ,999^99), ","))))

Can I use an arrayformula with a split arrayformula inside it?

Trying to break apart rows containing numbers like "198,183,158,315,274" by their comma, and then average them out and divide them by a singular number; using arrayformula. It only produces one row of result and it's incorrect though?
Here is my test sheet, editable
Thanks for any help.
try:
=ARRAYFORMULA({"Average"; IF(A4:A="",,
IFNA((MMULT(1*IFERROR(SPLIT(INDIRECT("A4:A"&
MAX(IF(A4:A="",,ROW(A4:A)))), ",")),
ROW(INDIRECT("A1:A"&COLUMNS(SPLIT(A4:A, ","))))^0)/
(1+LEN(REGEXREPLACE(A4:A&"", "[0-9\. ]", ))))/B1))})
spreadsheet demo
Another solution:
=ArrayFormula({"Average";(ArrayFormula(mmult(N(array_constrain(ArrayFormula(IFERROR(SPLIT(A4:A8,","))),MATCH(2,1/(A4:A8<>""),1),5)),sequence(Columns(ArrayFormula(IFERROR(SPLIT(A4:A8,",")))),1)^0)/mmult(N(array_constrain(if(ArrayFormula(IFERROR(SPLIT(A4:A8,",")))>0,1,0),MATCH(2,1/(A4:A8<>""),1),5)),sequence(columns(ArrayFormula(IFERROR(SPLIT(A4:A8,",")))),1)^0)))/$B$1})

Is it possible to transpose a column of text values into a single row without duplicates based on an if statement?

E.g. I have the following sheet and formula, but I only want to transpose the data if it contains a specific month, specified in A2.
try:
=TRANSPOSE(UNIQUE(FILTER(A5:A; B5:B=A2)))
You can use a query for that.
=TRANSPOSE(QUERY(A5:C, "select A where month(B)+2="&MONTH(A2)&""))
The reason we add +1 is because months in a query start from 0

How can I search a column with alphanumeric entries and return a 1 for unique with an array formula?

I need something that auto-fills for however many rows are in the spreadsheet, but I'm not sure if an array is the best way.
In my example below, I want Column C to show a 1 if the corresponding entry in Column A is unique, and a 0 if it isn't.
I had hoped it would be as easy as using ARRAYFORMULA(IF(UNIQUE(A1:A),1,0)), but forgot that IF wouldn't work with the text.
Here's my example with the most recent formula I tried.
Thank you!
Please use the following formula:
=ArrayFormula(IF(LEN(A1:A)<>0,
IF(COUNTIF(A1:A,A1:A)>1,0,1)
,""))
Functions used:
COUNTIF
ArrayFormula
LEN
You can combine ARRAYFORMULA and IF with IFERROR and COUNTIF
Sample:
=ARRAYFORMULA(IF(IFERROR(COUNTIF(A1:A,A1:A)=1,0)=TRUE,1,0))

Resources