Google Spreadsheets: Formula to "interleave" or "zipper" multiple arrays - google-sheets

Tried searching and checking Google documentation but I am still having issues getting the results that I want for this problem.
I'm needing to split several comma-separated lists of items and recombine them so that first items in each list is combined, followed by the second item, etc.
To ask with an illustration, if I have a cell with the following
Paul, John, George, Ringo
and another cell with the following
McCartney, Lennon, Harrison, Starr
How do I use one function to produce this in a cell?
Paul McCartney, John Lennon, George Harrison, Ringo Starr

Here you go, you will need to copy to every row - but assuming your data is in columns A and B it will work across a dynamic number of items:
=ARRAYFORMULA(join(",",split(A1,",")&" "&split(B1,",")))
See image example below, in row one i used the data you showed up top, and in row two i reversed the column data just to show as an example:

If you paste the first word CSV to Sheet1 and the second word CSV to Sheet2 then you could put the following into sheet3
In Cell A1:
=Sheet1!A1&" "&Sheet2!A1
This is saying take the value in sheet1 A1 and then a space " " then the value in sheet2 A1
You could also do this with the concatenate function:
=CONCATENATE(Sheet1!A1," ",Sheet2!A1)
Then just copy the formula to suit.

Related

How do I use a collection of individual cells instead of a range in a =lookup formula?

How do I modify this formula to work with information from cells 'AT4,AX4,BB4,BF4,BJ4,BN4' instead of the range 'AT4:BN4'
=lookup(1,ArrayFormula(1/(AT4:BN4<>"")),AT4:BN4)
In this linked spreadsheet, I only want the last exit price to automatically show in cell BS4, not the last cell value in the entire range.
google sheet spreadsheet example
I would appreciate any help.
I've added a new sheet ("Erik Help"). It's a duplicate of your original sample sheet.
Since you are really wanting to find the last "Price" per row for any number of rows, I used an array formula in BS4 that will accomplish this:
=ArrayFormula(IF(AS4:AS="",,1*REGEXEXTRACT(TRANSPOSE(QUERY(TRANSPOSE(IF((RIGHT(AT$3:BN$3,5)<>"Price")+(AT4:BN=""),,"~"&AT4:BN)),,COLUMNS(AT:BN))),"~([^~]+)$")))
Essentially, this will smash together each existing "Price" in a row (as determined by the word "Price" at the end of Row 3) prefaced by a tilde, forming one string, e.g.,
~9.5 ~11.5 ~13.5 ~10.65
That smash is accomplished with this:
TRANSPOSE(QUERY(TRANSPOSE([row information here]),,COLUMNS(AT:BN)))
Then REGEXEXTRACT will find the last tilde in the list and extract whatever is after it. The 1* will convert that to a number.

JOIN header row values across a row based on non-blank values in cells

So I have two rows:
ID
TagDog
TagCat
TagChair
TagArm
Grouped Tags (need help with this)
1
TRUE
TRUE
TagDog,TagArm
Row 1 consists mainly of Tags, while rows 2+ are entries. This data ties ENTRIES to TAGS.
What I'm needing to do is concatenate/join the tag names per entry. For example, look at the last column above.
I suspect we could write a formula that would:
Create an array of non-empty cells in the row. (IE: [2,4])
Return it with the header row A (IE: [A2,A4])
Then join them together by a comma
But I am unsure how to write the formula, or if this is even the best approach.
Here's the formula:
={
"Grouped Tags (need help with this)";
ARRAYFORMULA(
REGEXREPLACE(TRIM(
TRANSPOSE(QUERY(TRANSPOSE(
IF(NOT(B2:E11),, B1:E1)
),, COLUMNS(B1:E1)))
), "\s+", ",")
)
}
The trick used is called vertical query smash. That's the part:
TRANSPOSE(QUERY(TRANSPOSE(...),, Nnumber_of_columns))
You can find a brief description of this one and his friends here.
I wasn't able to create a single formula that would do this for me, so instead, I utilized a formula inside of Sheets' Find/Replace tool, and it worked like a charm!
I did a find/replace, replacing all instances of TRUE with the following formula:
=INDIRECT(SUBSTITUTE(LEFT(ADDRESS(ROW(),COLUMN()),3),"$","")&"$1")
What this formula does is it finds the cell's letter, then gets the first row of the cell using INDIRECT.
Breaking down the formula:
ADDRESS(ROW(),COLUMN()) returns the direct reference: $H$1
LEFT("$H$1",3) returns $H$
SUBSTITUBE("$H$","$","") replaces the dollar signs ($) and returns H
INDIRECT(H&"$1") references the exact cell H$1
Now, I can replace all instances of TRUE with that formula and the magic happens!
Here is a video explanation: https://youtu.be/SXXlv4JHDA8
Hopefully, that helps someone -- however, I would still be interested in seeing what the formula is for this solution.

Google Sheets: extracting numbers from multiple cells that contain text and numbers for one column of data?

I'm working in Google Sheets. I have a few hundred cells that contain text and numbers. The cells contain employee names and their ID#s. I want to extract the ID#s and compile them into one list. I have the formula below that will let me complete the task, but only for one cell, not for a range of cells (even if I select a range and add it to the formula):
=transpose(split(regexreplace(regexreplace(A1,"\s\d+\s"," "),"[^\d\.]"," ")," "))
For example, cell A1 would contain, "Tammy - 123456, Bob - 654987, Mike - 321456" and repeat similar until you get to something like cell DT75 "Marcus - 35768, Bruce - 95126, Lisa - 789123". Some cells in the sheet are blank. The above formula will give me the ID#s from A1 in their own cells:
123456
654987
321456
I'd like to get one column of all the ID#s in the sheet that I could then copy and paste into a completely different proprietary database. Am I coming at this the wrong way? Is a script a better angle?
Since you want your original range to be multi-column, you could try a slightly modified version of player0's formula, like this:
Use CONCATENATE to put all data in a single string.
REGEXREPLACE to remove everything but the numbers from your string.
SPLIT to divide your string into several cells, blank space being the separator.
FLATTEN put all resulting values into a single column.
=FLATTEN(SPLIT(REGEXREPLACE(CONCATENATE(A:DT), "[A-Za-z-,]+", )," "))
try:
=INDEX(FLATTEN(SPLIT(QUERY(REGEXREPLACE(A1:A, "[A-Za-z-,]+", ),,9^9), " ")))
for multi-column:
=INDEX(FLATTEN(SPLIT(FLATTEN(QUERY(REGEXREPLACE(A1:C, "[A-Za-z-,]+", ),,9^9)), " ")))

Split first name and rest of names in Google Sheets

I have a spreadsheet with a list of full names on column A and what I want to do is to split the first name of each person on column B and the remaining names (no matter how many there are) on column C. Any ideas?
I have a sample sheet if that helps:
https://docs.google.com/spreadsheets/d/1BJ7wdxYysklusPhWs85v3sUDrj4h68Z3h_16uoaWxj8/edit#gid=0
#Tulio, I've duplicated your first sheet, renamed it "Erik Help," and placed the following formula in B1:
=ArrayFormula({"First","The Rest";IF(A2:A="",,REGEXEXTRACT(A2:A,"^([a-zA-Z-]+) (.+)$"))})
As you can see, the column headers are created first, side by side. Then below that (signified by the semicolon), the REGEXEXTRACT pulls two parts from each non-null cell in A2:A — all letters from the start of the string up to the first space (which should be the first name), and then everything after that first space.
The other solution is more elegant/practical.
However, if you want to avoid regular expressions but consider a 2 simple formula solution, then use:
B2: =index(SPLIT(A2," ",true),1)
C2: =SUBSTITUTE(A2,concat(B2," "),"")
and drag them both down.
Output:

Count the Occurences of a text for the whole spreadsheet

I have a spreadsheet where in every column I have a list of names. They can repeat, and whats even worse - cells can contain some additional text (apart from the name).
What I want to do is count the occurrences of the name in the whole spreadsheet (only looking at the name, omitting the potential additional text). Is Possible?
I tried the formula =UNIQUE, but it does not work vertically (I'm working with Google Sheets)
Example of a document https://docs.google.com/spreadsheets/d/1STtJr0yisSeuv2w8_JVgQABAL5EDzI8aFmH8Vp2cOko/edit?usp=sharing
You can use Countif, Arrayformula, and Regexreplace to accomplish this task
Assuming you have the data range from A2:E12 and the prefilled unique names starting from A14
Formula:
=countif(ARRAYFORMULA(regexreplace($A$2:$E$12,".\(.*","")),A14)
Copy the formula until the last row
Hope it helps!
I'm sure that others will provide a much more elegant solution but this takes the data as presented in the spreadsheet and can be implemented in just a few minutes.
Paste this formula in Cell F3
=FILTER({A3:A13;B3:B6;C3:C5;D3:D5;E3:E5;A18:A21;B18:B20;C18:C20;D18:D20;E18:E19}, LEN({A3:A13;B3:B6;C3:C5;D3:D5;E3:E5;A18:A21;B18:B20;C18:C20;D18:D20;E18:E19}))
This creates a single column list compiled from the various smaller lists.
Highlight the range of names created in Column F (based on the test data = F3:F41), click Copy,
Highlight cell G3, click Paste special (Paste Values only) - this converts the formula to a list for entries.
Paste this formula in Cell H3 - this removes any data in brackets
=left(G3,iferror(search(" (",G3)-1,len(G3)))
Copy the formula down as many rows as there is data in Column G
Paste this formula in cell I3 - this lists the unique names
=unique(H3:H41)
Paste this formula in cell J3 and copy down as many rows as there is data in Column I - this counts the number of instances of each unique name in the master list.
=COUNTIF(H:H, I3)

Resources