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

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

Related

Unnest two columns in google sheet

I have a table like this one here (basically it's data from a google form with multiple choice answers in column A and B and non-muliple choice data in column C) I need a separate row for each multiple choice answer.
Column A
Column B
Email
A,B
XX,YY
1#gmail.com
A,C
FF,DD
2#gmail.com
I tried to un-nest the first column and keep the remaining columns like this
enter image description here
I tried several approaches I found with flatten and split with array formulas but I don't know where to start really.
Any help or hint would be much appreciated!
You can use the split function on the column A and after that, use the index function. Considering the table, you can use:
=index(split(A2,","),1,1)
The split function separate the text using the delimiter indicated, returning an array with 1 line and 2 columns; the index function will return the first line and the first column from this array. To return the second element from the column A, just change to
=index(split(A2,","),1,2)
I think there's no easy solution for this. You're asking for as many combinations of elements as multiple-choice elections have been made. Any function in Google Sheets has its potentials and limitations about how many elements it can express. One very useful formula here is REDUCE. With REDUCE and sequences of elements separated by commas counted with COUNTA, you can stablish this formula:
=QUERY(REDUCE({"Col A","Col B","Email"},SEQUENCE(COUNTA(A2:A)),LAMBDA(z,c,{z;LAMBDA(ax,bx,
REDUCE({"","",""},SEQUENCE(ax),LAMBDA(w,a,
{w;
REDUCE({"","",""},SEQUENCE(bx),LAMBDA(y,b,
{y;INDEX(SPLIT(INDEX(A2:A,c),","),,a),INDEX(SPLIT(INDEX(B2:B,c),","),,b),INDEX(C2:C,c)}
))})))
(COUNTA(SPLIT(INDEX(A2:A,c),",")),COUNTA(SPLIT(INDEX(B2:B,c),",")))})),
"Where Col1 is not null",1)
Since I had to use a "initial value" in every REDUCE, I then used QUERY to filter the empty values:

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?

Q: Transpose -> Merge(?) on 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)<>"")

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 Function That Sums Numbers In A Column When the Row Contains An EXACT Text

I've been at this problem for a while now. I am trying to sum numbers under a specific column when the rows equal a certain text and then display that sum on a different sheet. So far I came up with this formula: =IF(EXACT(A2,Table!A2:A)=TRUE,SUM(Table!C2:C)); however the only problem is that is sums everything in column C (which makes sense).
I wish there was a way to do something like the following: SUM(Table!C2:C where EXACT(A2,TABLE!A2:A)=TRUE). I've also tried the SUMIF(), DSUM(), and QUERY() functions to no avail. I must be getting logically tripped up somewhere.
Figured it out: =SUM(FILTER(Table!E4:E, EXACT(Table!A4:A,A4)=TRUE)).
=sum ( FILTER (b1:b10, a1:a10 = "Text" ) )
// the above formula will help you to take the sum of the values in column B when another column A contain a specific text.
The formula is applicable only in Google Spreadsheets

Resources