Google sheets - How to concat multiple values into multiple links - google-sheets

I am working with a google sheet that in one column can hold 1+ strings of numbers, and in another column, needs to read those numbers in and concat them with a link.
What I mean by this is and what works thus far: Column A - 324243324 || Column B - =concat("google.com/", Column A) = google.com/324243324
What I hope to get working: Column A - 324243324 5004938 || Column B - =concat("google.com/", Column A) = google.com/324243324 google.com/5004938
Is this possible? Thank you for your help!

You want to (a) split the input by spaces; (b) prepend each part by "google.com/"; and (c) join again, separated by spaces. This is achieved by
=join(" ", arrayformula("google.com/" & split(A1, " ")))
The & operator is equivalent to CONCAT but easier to type. arrayformula indicates that the operation is done on an array (the output of split).
However, these links will not be hyperlinked; joining makes them into plain text. To keep them functional, remove the last step, "join", so that each link appears in its own cell.

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:

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

Using multiple SUBSTITUTE functions dynamically

Let's say I have a list of strings and I want to remove specific words from them. I can easily use multiple SUBSTITUTE functions, for example, this will remove the strings in B2, B3 and B4 from the string in A2:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,$B$2,""),$B$3,""),$B$4,"")
How can I make this dynamic so that when I add more terms to remove in the B column they'll be removed automatically from A2. I tried the following methods but they didn't work:
1 - add the B cells as an array
=SUBSTITUTE(A2,{$B$2:$B$4},"") or =SUBSTITUTE(A2,{$B$2,$B$3,$B$4},"")
2 - Make a single condition
cat|donkey|mouse
3 - Using Indirect and concatenate - I built the correct function as a string (using REPT and CONCATENATE) and tried to activate it with INDIRECT) but this also failed.
Here's the spreadsheet (Col A are the strings to clea, B are the words to remove, D is the manual method that works, F, H and K are the failed 3 attempts).
https://docs.google.com/spreadsheets/d/15u8qZ0xQkjvTRrJca6AInoQ4aPkijccouAETE4Gyr9I/edit#gid=0
In the 'Copy' of the tab I entered
=ArrayFormula(IF(LEN(A2:A), REGEXREPLACE(A2:A, TEXTJOIN("|", 1, B2:B),),))
See if that works for you?
EXPLANTION
LEN(A2:A) basically limits the output to the rows that a value in column A
REGEXREPLACE uses a regular expression to replace parts of the string. That regular expression is constructed by the TEXTJOIN function.
TEXTJOIN combines the text from the range B2:B, with a specifiable delimiter separating the different texts. Here the pipe character (which means 'or' in regex) is used. The second paramater of this function is set to TRUE (or 1) so that empty cells selected in the text arguments won't be included in the result.
REFERENCES
TEXTJOIN
REGEXREPLACE
You can also try-
=TEXTJOIN(" ",TRUE,FILTER(SPLIT(A2," "),ISERROR(MATCH(SPLIT(A2," "),$B$2:$B$7,0))))

Extract unique values from a table in Google Sheet

I'm working on Google Sheet spreadsheets and I'm looking to get in a column the unique values of the table I show.
Suppose the table has the following values
A-B-C
B-C
A-D
With the Split function I can separate the values.
=SPLIT(B12;"-")
A B C
B C
A D
I'm stuck on the final point, which is to get the unique values.
A
B
C
D
In a single formula (sorted, no blanks):
=sort(unique(transpose(split(textjoin("-",1,A:A),"-"))))
Assuming your data is in columns A:C, =UNIQUE({A1:A3;B1:B3;C1:C3}).
You can also unbind the ranges. =UNIQUE({A:A;B:B;C:C}).
The curly braces {} combine the ranges.
The semi colons ; tell the curly braces to combine the ranges vertically into a single column for the UNIQUE function to parse.

Using Google Spreadsheets QUERY to Filter

I have the following google sheet where:
Col a= quantities
Col b= product codes, which i´ve split between C and H.
I want to know the quantity according to different "filters"... this filters are the fields between C11 and H11, and they are optional. There are 6 possible filters.
It works using =QUERY formula located in H12 and it returns the sum of quantity values where the filters match...
BUT there´s the possibility of leaving a filter empty to get "all"...
the query is as follows:
=QUERY(A1:H7, "select sum(A) where C contains '"&C11&"' and lower(D) contains lower('"&D11&"') and E contains '"&E11&"' and lower(F) contains lower('"&F11&"') and lower(G) contains lower('"&G11&"') and lower(H) contains lower('"&H11&"') ",-1)
My problem is with the match type: where C contains '"&C11&"' and...
instead of using "contains" it should compare using "matches". this way it would count like it should, but then it won´t accept empty filters.
How can I get it to count only if the field is filled??
What´s wrong with the filter right now? It´s counting "4" matches because model matches "1" happens when model is 1 or 21, also with column D where i´m looking for value X and is also counting value XN as it contains "X". if formula is changed to "matches" instead of "contains", it won´t allow me to leave it blank.
Thank you!
Karl_S formula is great, but it does not sum the quantities in column A. Adapting his approach to SUMIFS seems to do it:
=SUMIFS(A2:A7,C2:C7, IF(ISBLANK(C11), "<>" ,C11),D2:D7, IF(ISBLANK(D11), "<>" ,D11),E2:E7, IF(ISBLANK(E11), "<>" ,E11),F2:F7, IF(ISBLANK(F11), "<>" ,F11),G2:G7, IF(ISBLANK(G11), "<>" ,G11),H2:H7, IF(ISBLANK(H11), "<>" ,H11))
Use this formula instead:
=COUNTIFS(C2:C7, IF(ISBLANK(C11), "<>" ,C11), D2:D7, IF(ISBLANK(D11), "*",D11), E2:E7, IF(ISBLANK(E11), "<>",E11), F2:F7, IF(ISBLANK(F11), "*",F11), G2:G7, IF(ISBLANK(G11), "*",G11), H2:H7, IF(ISBLANK(H11), "*",H11))
If one of the options is blank, it will match all items in that column. Otherwise it should do an exact match.

Resources