Q: Transpose -> Merge(?) on google sheets - google-sheets

Trying to transpose data such that rows transpose into a single column stacking on top of each other.
=ARRAYFORMULA({TRANSPOSE(A1:C1);TRANSPOSE(A2:C2);TRANSPOSE(A3:C3)})
This formula essentially does what I want but what if I have many more rows? Would I need to enter; TRANSPOSE(Col(x):Col(y)) for every single row?
Any help is appreciated.

Please try:
=TRANSPOSE(SPLIT(TEXTJOIN(",",1,A:C),","))
Notes:
textjoin will join text and skip blanks. Add spaces in column C to have an empty row.
limit of join function is 50000 characters

Max Makhrov's answer is good, but indeed subject to the 50k limit. To get around that, I have recently found another method which is explained in my
interlacing answer to another question
In your case this would look something like this (up to arbitrary 9 rows):
=query(
sort(
{arrayformula({row(A1:A9)*3, A1:A9});
arrayformula({row(B1:B9)*3+1, B1:B9});
arrayformula({row(C1:C9)*3+2, C1:C9})}
),
"select Col2")

Am I missing something, or why does nobody suggest Flatten?
FLATTEN(A1:C3)
And you can use Filter as usual to filter out blank cells, e.g.
=FILTER(FLATTEN(A1:C3);FLATTEN(A1:C3)<>"")

Related

How can I sort a column horizontally into transposed rows with matching prefixes?

I have a google sheet column with data that looks like this. ID numbers with count suffixes. How can I transpose them horizontally into rows on a sheet sorted/grouped/filtered by their ID number into the appropriate number of columns matching their suffix number?
Sheet Link:
https://docs.google.com/spreadsheets/d/1wq3Zrh5wE_IHP2utvMeFRHrMe1qra2ppq_G7PrSt-jY/edit?usp=sharing
What I have
INV46673-1
INV46673-2
INV56184-1
INV56184-2
INV56184-3
INV56184-4
INV56184-5
INV68328-1
INV68328-2
INV68328-3
INV68328-4
INV68347-1
INV68347-2
INV68347-3
What I need
INV46673-1
INV46673-2
INV56184-1
INV56184-2
INV56184-3
INV56184-4
INV56184-5
INV68328-1
INV68328-2
INV68328-3
INV68328-4
INV68347-1
INV68347-2
INV68347-3
If sheets has an off the shelf function for this I have not been able to find it. I have tried pivot tables, Hlookup, filtered arrays etc. I am grateful for any advice I may receive. A solution that uses a fixed character count (8) will work but I would love to see something that actually uses the exact ID number.
Try the following formula-
=INDEX(SPLIT(BYROW(UNIQUE(INDEX(SPLIT(A2:A15,"-"),,1)),LAMBDA(x,JOIN("|",SORT(FILTER(A2:A15,INDEX(SPLIT(A2:A15,"-"),,1)=x))))),"|"))
Here's another approach:
=index(let(a,regexextract(A2:index(A:A,counta(A:A)),"(.*)-(\d+)"),b,unique(index(a,,1)),c,max(--index(a,,2)),makearray(counta(b),c,lambda(r,x,xlookup(index(b,r)&"-"&index(sequence(1,c),,x),A:A,A:A,)))))

Processing a list to output in a particular format

I am processing a list to output its items in chunks separated by blank rows as follows. But the result is not working when there are similar items, as shown with the arrows.
The formula I'm using is =query(filter(flatten({if(COUNTIFS($A$1:$A,$A$1:$A,ROW($A$1:$A),"<="&ROW($A$1:$A))=1," ",),A1:A}),flatten({if(COUNTIFS($A$1:$A,$A$1:$A,ROW($A$1:$A),"<="&ROW($A$1:$A))=1," ",),A1:A})<>""),"offset 1",0)
I need some help with it, to get the repeated chunks right too, so that the desired result is following. I've tried tweaking the COUNTIF conditions but am struggling.
Desired result
try:
=INDEX(LAMBDA(a, QUERY(FLATTEN(SPLIT(QUERY(IFERROR(
IF(a={""; a},"×"&a,"×​×"&a)),,9^9), "×")), "offset 1", ))
(A1:INDEX(A:A, MAX(ROW(A:A)*(A:A<>"")))))
When I opened it, there was no answer but here it goes all the same for you or another user 😉
It checks each row with the next one and adds a "|" when they differ, then joins all rows with that same symbol and split by that same symbol, resulting in empty rows between different values
=transpose (split(join("|",byrow(A1:A,lambda(each,if(each="","",SI(each=offset(each,1,0),each,each&"|"))))),"|",1,0))
Here's another solution:
=index(lambda(a,b,query(flatten(split(
a&if(a=b,,"❆ "),"❆")),"where Col1<>''"))
(filter(A:A,A:A<>""),{filter(A2:A,A2:A<>"");0}))

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))), ))

Transpose column and add separator column

I'm trying to transpose a column from one sheet into a row of another sheet with a new blank column separating each result
=TRANSPOSE(Sheet1!A1:A30)
Whats the easist way to achieve this without having to add a blank row between each of the rows in the orginal sheet
Thanks
I think this may be the easiest way
split(textjoin("||",,Sheet1!A1:A30),"|",,false)
This answer is based on Toms answer:
split(textjoin("||",,Sheet1!A1:A30),"|",,false)
I like the solution because it is simple.
More general question would be:
How to add N extra separator columns with a formula
Here's the formula:
=TRANSPOSE(SPLIT(JOIN("|"&rept("|",1),A1:A30),"|",1,0))
where
"|" is a rare char you do not have in your dataset
rept("|",1) is to get N separator columns. Change 1 to N.
The only problem with the formula is join function limit on 50000 characters.
The final function won't give the error with a large dataset.
Please try:
=TRANSPOSE(ArrayFormula(TRIM(SPLIT(QUERY(A1:A30&"|"&rept("|",1),,2^99),"|",1,0))))
query replaces join and have no limits
trim is needed because query creates spaces at the end of each line.
Going further in depth on the issue above (question):
What would you write if you want a certain text for each new column:
E.g. I have several datasets (columns) with 1) drilling resistance and 2) associated depths, all of which I will extract from another sheet into this new one.
I have a list of boreholenames which I will transpose and insert as text over the columns with 1).
Then I want to add a column for each borehole with the height (2). How do I then automatize adding text for each new column with the writing "height (m.a.s.l.) boreholenumber", where the latter could be just picked from the borehole name list.
And by the way. The split function doesn't exist in my excel-program :( How to I get it?

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.

Resources