Duplicating data in one cell as per repeat counter - google-sheets

I got into a bit of problem. I have data like this
Date Repeat
7-Oct-2018 1
8-Oct-2018 1
9-Oct-2018 2
10-Oct-2018 2
11-Oct-2018 3
12-Oct-2018 2
13-Oct-2018 1
Now the result i want is a column where the date is repeated as per the repeat numbers, like this.
Result
7-Oct-2018
8-Oct-2018
9-Oct-2018
9-Oct-2018
10-Oct-2018
10-Oct-2018
11-Oct-2018
11-Oct-2018
11-Oct-2018
12-Oct-2018
12-Oct-2018
13-Oct-2018
So how can i get this result. Please do help

I tried to think of it for own study. For example, how about this sample formula? I think that there might be simpler formulas. So please think of this as one of them. When you use this, please put the following formula to a cell.
=TRANSPOSE(SPLIT(JOIN(",",ARRAYFORMULA(REPT(A2:A8&",",B2:B8))),","))
This formula supposes that the values of Date and Repeat are put in A2:A8 and B2:B8, respectively.
Show repeatedly Date using REPT(). At this time, , is used as a delimiter.
Join each cell with , using JOIN().
Split the cell with , using SPLIT().
Transpose the cells using TRANSPOSE().
I think that you can also use CONCATENATE() and TEXTJOIN() for joining cells.
References:
REPT
JOIN
SPLIT
TRANSPOSE
CONCATENATE
TEXTJOIN

Related

Google Sheets: Is there a way to make an Array for a sequence that grows to a repeat given number of times

I have managed to make this formula:
=IF(COUNTIF($A$1:A1,A1)=$B$1,A1+1,A1)
Is making an incremental list in the same column, starting with 01, and on cell B1 I am instructing how many times this number should repeat (up to 5 times per number). So, if I say repeat 2 times it looks like this:
Column A
1
1
2
2
How can I make it an Array Formula? I'm barely starting on Arrays so I'm just trying to learn as I go.
you can try to solve this with the following formula =ArrayFormula(flatten(if(SEQUENCE(1,C1),SEQUENCE(C2)))) but you should specify the value limit in cell C2 to which the numbers must increase, otherwise the formula will loop
Try this
=ARRAY_CONSTRAIN(arrayformula(query(flatten(split(rept("|"&A2:A,B2:B),"|")),"select * where Col1 is not null")),SUM(B2:B),1)
https://docs.google.com/spreadsheets/d/1qXy-hzWUnsUmAa-8aV5IHOyZABGD_h8ajICLwdyNge8/edit?usp=sharing
Try Sequence() with ROUNDUP() function.
=ArrayFormula(ROUNDUP(SEQUENCE(B1*B1)/B1,0))
When enter 3:

Formula that will skip one column when calculating SUM() or similar functions

I'd like to run a =SUM(A1:G1), but always skip one column, regardless if it has value or not.
In this case, it should calculate A1+C1+E1+G1.
Is there another function I could append to SUM() or other similar functions as SUM in order to skip one column?
Thank you!
Using the following method you can calculate any number of alternate columns, without the need of manual +
Suppose your data is in second row onwards, use this formula
=SUMPRODUCT(A2:G2, MOD(COLUMN(A2:G2),2))
Simply a sumproduct of cell values and a array of {1,0,1,0,1...}
Another slight variation
=SUMPRODUCT(A2:G2*ISODD(COLUMN(A2:G2)))
But if the even columns contain letters instead of numbers this will give an error, so you can use instead
=SUMPRODUCT(N(+A1:G1)*ISODD(COLUMN(A1:G1)))
Comparing #AnilGoyal's answer, this works as well
=SUMPRODUCT(A1:G1,--ISODD(COLUMN(A1:G1)))
You can use:
=SUM(INDEX(A1:G1,N(IF(1,{1,3,5,7}))))
Or with Excel O365:
=SUM(INDEX(A1:G1,{1,3,5,7}))
A bit more of a general solution:
=SUMPRODUCT(MOD(COLUMN(A1:G1),2)*A1:G1)
Or with Excel O365:
=SUM(MOD(COLUMN(A1:G1),2)*A1:G1)
Or even:
=SUM(INDEX(1:1,SEQUENCE(4,,1,2)))
Since you included Google-Sheets, I'll throw in an option using QUERY():
=SUM(QUERY(TRANSPOSE(1:1),"Select * skipping 2"))
Maybe a bit more verbose, but very understandable IMO.
Consider something of the format:
=SUM(A1:G1)-INDEX(A1:G1,2)
The 2 in the formula means remove the 2nd item in the part of the row. (so the 999 is dropped)
So the formula =SUM(BZ10:ZZ10)-INDEX(BZ10:ZZ10,2) drops CA10 from the sum, etc.(a similar formula can be constructed for columns)
google sheets:
=INDEX(MMULT(N(A1:H3), 1*ISODD(SEQUENCE(COLUMNS(A:H)))))
=INDEX(IF(ISODD(COLUMN(A:H)), TRANSPOSE(MMULT(TRANSPOSE(
IFERROR(A1:H3*ISODD(COLUMN(A:H)), 0)), 1^ROW(A1:A3))), ))

Arrayformula Running Total with multiple columns

I've got the following task to solve, but I can't wrap my head around it.
There are a couple of numbers for different years. I would like to have a running total sum of all columns (= range C:I) in column J. I can do that with a formula in every cell of J - however I need to achieve it with a single arrayformula in J2.
What i figured after a lot of research are 2 steps:
replace empty cells with 0s, since arrayformulas obviously have some problems with empty cells
make a sum of each row
For step 1 the formula is: =ARRAYFORMULA(IF(ISBLANK(C2:I15),0,C2:I15)) which gives me back a temporary array like:
As this is a 15x7 array, I need something like a 7x1 array to multiply with in order to get a 15x1 array.
That formula would be: =ARRAYFORMULA(TRANSPOSE(COLUMN(C1:I1)^0))
So in the end my formula so far look like: =ARRAYFORMULA(MMULT(IF(ISBLANK(C2:I15),0,C2:I15),TRANSPOSE(COLUMN(C1:I1)^0)))
And this results in a 15x1 array that gives me the sum per row, but not a total running sum of all rows.
This is where I am stuck - any help and ideas are greatly appreciated.
EDIT: added a shared version for you to fiddle: https://docs.google.com/spreadsheets/d/1cqNEsWHqBaHdDrMY8x4DUKpEkYprRZ8AibEe7d0knPY/edit?usp=sharing
I think this will work too:
=ARRAYFORMULA(IF(B2:B="";;SUMIF(SEQUENCE(ROWS(C2:I);COLUMNS(C2:I));"<="&SEQUENCE(ROWS(C2:I);1;COLUMNS(C2:I);COLUMNS(C2:I));C2:I)))
try:
=ARRAYFORMULA(IF(B2:B="";;MMULT(TRANSPOSE((ROW(M2:M)<=TRANSPOSE(ROW(M2:M)))*
MMULT(C2:I*1; ROW(A1:A7)^0)); SIGN(MMULT(C2:I*1; ROW(A1:A7)^0))^0)))

Google Sheet - Transform two columns into one column using arrayformula (more than 50,000 characters)

I'm using Google Sheets and looking for an arrayformula that able to take a list in two columns and arrange it alternately in one column. The sheet contains about 5,000 rows, each row has more than 35 characters.
I tried this:
=transpose(split(join(" ", query(transpose(B5:C),,50000)), " "))
But then I got this message:
Please take a look at the sheet here:
https://docs.google.com/spreadsheets/d/11T1Roj1trviOSiiTZS292-4l3oODid7KLi9oGz3Z66o/edit#gid=0
Assuming your 2 columns are A and B, this formula will "interlace" them:
=query(
sort(
{arrayformula({row(A1:A3)*2, A1:A3});
arrayformula({row(B1:B3)*2+1, B1:B3})}
),
"select Col2")
Explanation, unwrapping the formula from the inside:
Each value gets a unique number, based on its row number times 2 (+1 for the 2nd column)
Everything is sorted based on this number
Only the 2nd column is extracted for the result.
There is a function for this called FLATTEN().
This works perfectly as a general solution since it takes an array of any size and outputs the items in the order they appear left-right-top-down (See here).
It can be combined with TRANSPOSE() to accomplish the same thing but in the horizontal case, and if needed blank cells can be omitted with FILTER().
EDIT:
My sincere apologies, I did not read the question carefully enough. My response is incorrect.
This should work:
={B5:B12;C5:C12}
just be careful to NOT change it to
={B5:B;C5:C}
This will start an infinite loop where the spreadsheet will increase the amount of rows in the spreadsheet to allow this output column to expand, but in doing so increases the length of the 2 input columns, meaning the length of the output column increases even more, so the spreadsheet tries adding more rows, etc, etc. It'll make your sheet crash your browser or something each time you try to open it.
In Row5:
=ArrayFormula(offset(B$5,INT((row()-5)/2),iseven(row())))
Would need to be copied down however.

Google spreadsheet, passing parameter

Okay, I'm an huge noob with that kind of stuff, and I don't really know where to begin with. Google help is somehow not enough :/.
I want to make a conditionnal count on a single column :
COUNTIF(A1:A10, "3")
It will return the number of 3 in the cells from A1 to A10. Now the problem is, there can be multiples values in each cell formatted like this : "1; 3; 5". I can easily match this using regex :
B1 = REGEXEXTRACT(A1,"3")
Then repeat and sum on the second column. Now, how can I do this using a single formula?
COUNTIF(A1:A10, REGEXEXTRACT(A1:A10,"3"))
This doesn't work because regexextract take as an input a single cell. I would like to tell it to use the same cell than in the countif, but I have no clue on how to achieve this.
you can have regextract working on an array. E.g.:
=ArrayFormula(sum(--regexmatch(A2:A&"", "3")))
should count all threes (either single or in cells with multiple values), but in case you have multiple threes in one cell, you may need to use something like this:
=ARRAYFORMULA(sum(len(A:A)-len(SUBSTITUTE(A:A,"3","")))/len("3"))
This should work:
=COUNTIF(SPLIT(JOIN(";",A:A),";"),"3")

Resources