Combine Data From Separate Columns with a Delimiter with Arrayformula - google-sheets

This is the example sheet.
Alright, in cell V1!A1 is the formula ={"Languages";ARRAYFORMULA(TRANSPOSE(QUERY(TRANSPOSE(B2:F&","),,COLUMNS(B2:F))))}. I need to combine data from B2:F with the delimiter ,. But now I need to delete the unnecessary delimiters.
In sheet V2, I tried ={"Languages";ARRAYFORMULA(REGEXREPLACE(REGEXREPLACE(TRANSPOSE(QUERY(TRANSPOSE(B2:F&","),,COLUMNS(B2:F))),"(^(,(\s,){4})$)|(^(,\s)+)|(,(\s,)?\s?$)",""),"(,\s,)+\s?",", "))} but it's not consistant and still leaves delimiters in the output.
Is there a better way to do this?

I added a sheet called "Erik Help" which replaces your formula with the following:
=ARRAYFORMULA({"Languages";SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(B2:F&" "),,COLUMNS(B2:F))))," ",", ")})
Essentially, instead of appending a comma to elements of the range B2:F, I appended a space. Then I applied TRIM to the results, which will leave no spaces before or after each concatenation and only one between each element. To that, I applied a SUBSTITUTE of the single spaces with a comma-space.

Related

Capitalize only words with more than 2 characters on Google Sheets

How can I capitalize only words with more than a specific count of characters? Google Sheets formula PROPER capitalizes all the words without any exclusions. For example, I would like to omit the capitalization of an acronym such as "PC" or "RAM" that is contained within a string in a cell.
Capitalize All and exclude from a list
To be able to PROPER()/Capitalize the input of words and exclude others:
Use this formula, but first we need the excluded list "Acronyms excluded".
=ArrayFormula(IF(
REGEXMATCH(TEXTJOIN("^_~",,UNIQUE($D$2:$D)), UPPER(A2:A))<>TRUE,PROPER(A2:A),A2:A))
Capitalize only words more than 2 charachters long
=ArrayFormula(IF(A2:A="",,
IF(LEN(UPPER(A2:A))<=2,
UPPER(A2:A),PROPER(A2:A))))
I may have been overthinking this by a mile, but try:
Formula in B1:
=INDEX(SUBSTITUTE(TEXTJOIN("",0,IF(LEFT(SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|"))="♣",SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|"),PROPER(SPLIT(REGEXREPLACE(A1,"\b(RAM|[A-Za-z]{1,2})\b","|♣$1|"),"|")))),"♣",""))
The point here is that \b(RAM|[A-Za-z]{1,2})\b would capture any 1-2 character word made of word-characters between word-boundaries or RAM. Now you can add any exclusion into the alternation of the pattern through concatenating more |. The replacement includes a backreference to the capture group to encapsulate the substring between a delimiter to split on and a leading unique character. The IF() will then check whether or not any element from the resulting SPLIT() needs to be processed with Proper() or not.
Note: Word-boundaries like \b may not be safe when you'd have data like hello-pc and you'd want this to be processed with PROPER(). A small adjustment to the formula is then needed.

How can I get this formula to grab values between the commas?

Here is a screenshot of and a link to my test spreadsheet. It makes the requirements very clear:
https://docs.google.com/spreadsheets/d/1rZr2zHaSkff9SFpwpx83_4TawruotA1jhOKqW6uYDz0/edit?usp=sharing
The formula I have come up with is very close to what I need, but "linkText" is a placeholder for the value of the array item. Here is my formula:
=if(A2="","","<a href='https://samplewebsite.com/search?q=" & trim(lower(substitute(A2,",","'>linkText</a>, <a href='https://samplewebsite.com/search?q="))) & "'>linkText</a>")
try:
=index(join(","&char(10), SUBSTITUTE($B$1, "linkText", split(A3, ","))))
Drag down to column.
Result:
First using SPLIT to split the strings between comma from the column A. Then using SUBSTITUTE to find the string "linkText" from the text in B1 and replace it with the strings from the returned strings from the split function. Then joining them all together.
NOTE: Just keep the reference string in a fixed cell in your sheet. <a href='https://samplewebsite.com/search?q=linkText'>linkText</a> to be used in the formula. As seen in above screenshot it is fixed in cell B1.
Alternate Solution using ArrayFormula:
You can also use it with arrayformula so you only have to put it in the first row and no need to drag down the formula to the column, it will automatically be expanded down just make sure to clear the cells below or it will throw an error.
=arrayformula(regexreplace(substitute(transpose(query(transpose(IF(IFERROR(SPLIT(A2:A, ","))<>"", "♦<a href='https://samplewebsite.com/search?q="&SPLIT(A2:A, ",")&"'>"&SPLIT(A2:A, ",")&"</a>", )),,9^9)), "♦", char(10)), "^\s", ""))
Result:
You may also have a look in below references for more information.
References:
SUBSTITUTE
SPLIT
JOIN
Comma separated list into matched columns pairings

ArrayFormula, RegexExtract, and Join in Google Sheets

I have a data set wherein emails are populated. I would like to list all the surnames extracted in the emails per cell and will be all joined to a one single cell but I want to put a separator or delimeter to the emails obtaine per cell.
Here is the data set:
A
B
john.smith#gmail.com, jane.doe#gmail.com
UPDATE
john.smith#gmail.com
CLOSE
And here is the formula to extract
=ARRAYFORMULA(
PROPER(
REGEXEXTRACT(
A:A,
REGEXREPLACE(
A:A,
"(\w+)#","($1)#"
)
)
)
)
This initially yields the ff:
C
D
Smith
Doe
Smith
I would like to use JOIN() inside the ARRAYFORMULA() but it is not working as I seem to think it would since it outputs an error that it only accepts one row or one column of data. My initial understanding of ARRAYFORMULA() is that it iterates through the course of the data, so I thought it will JOIN() first, and then move on to the next element/row but I guess it doesn't work that way. I can use FLATTEN() but I want to have delimiters or separators in between the row elements. I need help in obtaining my intended final result which will look like this:
UPDATE:
Smith
Doe
CLOSE:
Smith
All are located in one cell, C1. UPDATE and CLOSE are from column B.
EDIT: I would like to clarify that the email entries in column A are dynamic and maybe more than two.
I think this will work:
=arrayformula(flatten(if(A2:A<>"",regexreplace(trim(split(B2:B&":"&char(9999)&regexreplace(Proper(A2:A),"#[\w\.]+,\ ?|#.*",char(9999)&" "),char(9999))),".*\.",),)))
NOTES:
Proper(A2:A) changes the capitalisation.
The regexreplace "#[\w\.]+,\ ?|#.*" finds:
# symbol...
then any number of A-Z, a-z, 0-9, _ [using \w] or . [using \.]
then a comma
then 'optionally' a space \ [the optional bit is ?]
or [using |], the # symbol then an number of characters [using .*]
The result is replaced with a character that you won't expect to have in your text - char(9999) which is a pencil icon, and a trailing space (used later on when the flatten keeps a gap between lines). The purpose is to get all of the 'name.surname' and 'nameonly' values in front of any # symbol and separate them with char(9999).
Then infront of the regexreplace is B2:B&":"&char(9999)& which gets the value from column B, the : chanracter and char(9999).
The split() function then separates then into columns. Trim() is used to get rid of spaces in front of names that don't contain ..
The next regexreplace() function deletes anything before, and including . to keep surname or name without ..
The if(A2:A<>"" only process rows where there is a value in col A. The arrayformula() function is required to cascade the formula down the sheet.
I didn't output the results in a single cell, but it looks like you've sorted that with textjoin.
Here's my version of getting the results into a single cell.
=arrayformula(textjoin(char(10),1,if(A2:A<>"",REGEXREPLACE(B2:B&":"&char(10)&regexreplace(Proper(A2:A),"#[\w\.]+,\ ?|#.*",char(10)),".*\.",),)))
Assuming that your A:A cells will always contain only contiguous email addresses separated by commas, you could place this in, say, C1 (being sure that both Columns C and D are otherwise empty beforehand):
=TRANSPOSE(FILTER({B:B,IFERROR(REGEXEXTRACT(SPLIT(PROPER(A:A),","),"([^\.]+)#"))},A:A<>""))
If this produces the desired result and you'd like to know how it works, report back. The first step, however, is to make sure it works as expected.
use:
=INDEX(REGEXREPLACE(TRIM(QUERY(FLATTEN(QUERY(TRANSPOSE({{B1; IF(B2:B="",,"×"&B2:B)},
PROPER(REGEXEXTRACT(A:A, REGEXREPLACE(A:A, "(\w+)#", "($1)#")))})
,,9^9)),,9^9)), " |×", CHAR(10)))

Extract dollar amount in sheets text cell

Ideally what I'm looking for is to get the dollar amount extracted no matter the format.
Sheet link:
https://docs.google.com/spreadsheets/d/1drTPlnQmVTsbUXwJDfQr7DnHjSbnGx-fLthad6KxfM8/edit?usp=sharing
Delete everything from Column B, including the header. Then place the following formula in cell B1:
=ArrayFormula({"Header"; IF(A2:A="",,VALUE(IFERROR(REGEXEXTRACT(A2:A,"\$(\d+\.?\d*)"))))})
You may change the header text within the formula as you like.
If a cell in A2:A is blank, the corresponding cell in B2:B will be left blank as well.
Otherwise REGEXEXTRACT will look for a pattern that begins with a literal dollar sign. The parenthesis within the quotes denote the beginning and end of a capture group (i.e., what will be returned if found) following that literal dollar sign. The pattern \d+\.?\d* means "a group of one or more digits, followed by zero or one literal period symbols, followed by zero or more digits."
IFERROR will cause null to be rendered instead of an error if such a pattern is not able to be extracted.
VALUE will convert the extracted string (or null) to a real number.
If you would prefer that null be returned instead of 0 where no pattern match is found, you can use the following variation of the formula instead:
=ArrayFormula({"Header"; IFERROR(VALUE(IFERROR(REGEXEXTRACT(A2:A,"\$(\d+\.?\d*)"),"x")))})
If your strings may include numbers with comma separators, use the following versions of the above two formulas, respectively:
=ArrayFormula({"Header V1"; IF(A2:A="",,VALUE(IFERROR(REGEXEXTRACT(SUBSTITUTE(A2:A,",",""),"\$(\d+\.?\d*)"))))})
=ArrayFormula({"Header V2"; IFERROR(VALUE(IFERROR(REGEXEXTRACT(SUBSTITUTE(A2:A,",",""),"\$(\d+\.?\d*)"),"x")))})
try:
=INDEX(IFNA(REGEXEXTRACT(A2:A, "\$(\d+.\d+|\d+)")*1))

Random Cells From A List In Google Sheets

Sample
Code:
=ArrayFormula((VLOOKUP(QUERY(UNIQUE(RANDBETWEEN(ROW(INDIRECT("A1:A"&COUNTA(A:A)*10))^0;COUNTA(A:A)));"limit 4");{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A;A:A<>"")};2;0)))
I'm trying but got this error,
test 1
Can anyone tell what's wrong? To make my code
to work as in the first picture
error in #REF!
VLOOKUP evaluates outside the range bounds.
im try change code
=ArrayFormula((VLOOKUP(QUERY(UNIQUE(RANDBETWEEN(ROW(INDIRECT("A1:A"&COUNTA(A:A)*10))^0,COUNTA(A:A))),"limit 4"),{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A,A:A<>"")},1,0)))
but number
solution for that?
=ARRAYFORMULA(VLOOKUP(FLOOR(RANDARRAY(5)*COUNTA(A2:A)),{SEQUENCE(COUNTA(A2:A),1,0),A2:INDEX(A2:A,COUNTA(A2:A))},2))
Create 5 random integers using RANDARRAY between 0(inclusive) and number of entries in A2:A(i.e., COUNTA)(exclusive).
Create a artificial side by side array({arr1,arr2}) of SEQUENCE of numbers (from 0) and actual values in A2:A
VLOOKUP the random integers in the created artificial array to give random values in A:A
If you're in locales that use comma as decimal separators, The artificial array should be created using \ instead of ,({arr1\arr2}).
=ARRAYFORMULA(VLOOKUP(FLOOR(RANDARRAY(5)*COUNTA(A2:A));{SEQUENCE(COUNTA(A2:A);1;0)\A2:INDEX(A2:A;COUNTA(A2:A))};2))
On the first formula
{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A;A:A<>"")}
replace the semicolon ; between INDIRECT() and FILTER() by a backslash \ as using a semicolon appends the results of FILTER to the results of INDIRECT but you are looking to put the results of each function on their own column. Please note that this formula is using semicolons as argument separator.
On the second formula replace the semicolon ; between INDIRECT() and FILTER() by a comma , (and replace the third argument of VLOOKUP, 1, by 2. Please note that this formula is using commas as argument separators.
Explanation
Commas are used as argument separator on spreadsheets that use dot as decimal separator (=SUM(1,2,3)) but also use commas as columns separator on arrays ({"a","b"})
Semicolons are used as argument separator on spreadsheets that use comma as decimal separator (=SUM(1;2;3)). On these spreadsheets, backslashes are used as columns separator on arrays ({"a"\"b"});
References
Using arrays in Google Sheets

Resources