I'm using an ARRAYFORMULA / TEXTJOIN formula in Google Sheets to pull selected data together to make a single line of code arranged in a specific way for my project.
The resulting array needs to both INCLUDE commas in the first half, as well as EXCLUDE commas towards the end of the same formula.
example of commas needing removed
I'm currently using a ", " at the beginning of my TEXTJOIN, which works for placing a , between each cell, however I also need the last few cells (in this case: I9, O5, O6, O7, O8) to not have any commas between them.
Is there a way to do this?
Thank you in advance!
Here is a demo of what I'm working on:
https://docs.google.com/spreadsheets/d/1gTQiNKy4c376FuIWQQAomlJ6J1utCOjuq6JzRplTSu4/edit?usp=sharing
Option 01
=TEXTJOIN(", ",1,
TEXTJOIN(", ",1,C5:F8),
TEXTJOIN(", ",1,C3,I5))&", "&
TEXTJOIN(", ",1,I6:L9)&" "&
TEXTJOIN(" ",1,O5:O8)
Option 02
Use this formula to replace the last set of commas
=REGEXREPLACE(B12,
REGEXEXTRACT(B12&"", " --ar.+?(,.+)"),
REGEXREPLACE(REGEXEXTRACT(B12&"", " --ar.+?(,.+)"), ",", ""))
Try this simpler formula (based on your formula)
=INDEX(concatenate("signal code: ",
TEXTJOIN(", ",1,C5:C8,C3,I5:I8) & " "
& TEXTJOIN(" ", 1,I9, O5, O6, O7, O8)))
I got the answer from Reddit:
If your formula is:
=ARRAYFORMULA(concatenate("signal code: ",TEXTJOIN(", ",TRUE,
$C$5:$F$5,$C$6:$F$6,$C$7:$F$7,$C$8:$F$8,$C3,$I5,$I6:L6,
$I7:L7,$I8:L8,$I9,$O5, O6, O7, O8)))
Then just change the separator (in this example, a space) for those
few:
=ARRAYFORMULA(concatenate("signal code:",TEXTJOIN(",",TRUE,
$C$5:$F$5,$C$6:$F$6,$C$7:$F$7,$C$8:$F$8,$C3,$I5,$I6:L6,$I7:L7,
$I8:L8)& " " & TEXTJOIN(" ", TRUE, $I9, $O5, O6, O7, O8)))
Related
This question already has an answer here:
Concatenate non empty cells in each row with arrayformula in google sheets
(1 answer)
Closed 6 months ago.
The shared sheet shows multiple column rows which can be individually concatenated horizontally with a comma & space between using TEXTJOIN(", ", TRUE, A2:D2) and blank spaces are ignored. But textjoin cannot be used in Arrayformula as far as I know and I would like ot find a suitable replacement that can also be combined as a string along with other strings of information.
I want to be able to use this as an independent formula string that might be added to other strings of information. For example, "Favorite colors: "& textjoin(", ",1,A2:D2)&"Favorite foods:"&textjoin(", ",1,E2:G2)&"...
Possible solutions
May be a variant of one of the following:
Modifying this so it could be used w/ an array formula JOIN("~", SPLIT(JOIN(CHAR(60000), B3:E3), CHAR(60000)))
Modifying this formula works with join also JOIN(", ",FILTER(H2:H,H2:H<>""))
Using a combination of IF(a2:A<>"" along with a regex replacement at the end (see my answer below) but this could be very long formula compared to textjoin if there are many columns)
An ideal solution would be concise and look closest to something this:
arrayformula(TEXTJOIN(", ", TRUE, A2:A,B2:B,C2:C)
Shared sheet is here
use:
=INDEX(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(IF(A2:D="",,A2:D&",")),,9^9))), ",$", ))
Using a series of IF statements, adding a delimiter and then removing any trailing delimiters can be accomplished using: Arrayformula(regexreplace(if(A2:A100<>"",A2:A100&", ","")&if(B2:B100<>"",B2:B100&", ","")&if(C2:C100<>"",C2:C100&", ","")&if(D2:D100<>"",D2:D100&", ",""),", $",""))
Use a query smush, like this:
=transpose(query(transpose(A2:D), "", 9^9))
The formula will separate values with spaces. To separate with commas and remove unwanted white space, use trim() and substitute() or regexreplace(), like this:
=arrayformula( substitute( trim( transpose( query( transpose(A2:D), "", 9^9 ) ) ), " ", ", " ) )
All,
I have been trying to import a range from a different sheet and concatenate two row/columns into one on import and I am failing at it horribly.
Here is the code I am using:
=IMPORTRANGE(("14ZDhy0VE-u0srsp1EZG6KaxMOusF8TzCcD2yWxPoxM0", "Aluminum!B1:H"),CONCATENATE(D:D,"","x","",E:E))
The image below shows the two columns and rows highlighted that need to be combined.
Column Highlight
Best,
D
try:
=INDEX(SUBSTITUTE(FLATTEN(QUERY(TRANSPOSE(IMPORTRANGE(
"14ZDhy0VE-u0srsp1EZG6KaxMOusF8TzCcD2yWxPoxM0", "Aluminum!D1:E")),, 9^9)), " ", " x "))
I'm importing a .csv file with the IMPORTDATA function. The separator is ; and decimal char , on which Google Sheets automatically applies a text to column. I guess this is the expected behavior from IMPORTDATA but as a result, my file is not correctly parsed.
I've tried to use the substitute function on , with . but I guess that the text to the column is applied within the IMPORTDATA function.
=ARRAYFORMULA(SPLIT(SUBSTITUTE(IMPORTDATA("https://drive.google.com/uc?export=download&id=1hosZrfgrKnJJgXkgmPZSKdFoYV_AxKJS"), ",", "."), ";"))
Is there any way to import a CSV with ; as a separator and , as a decimal symbol using a single formula?
I've seen solutions using multiple sheets but I'd like to keep it simple.
=ARRAYFORMULA(SPLIT(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IMPORTDATA(
"https://drive.google.com/uc?export=download&id=1hosZrfgrKnJJgXkgmPZSKdFoYV_AxKJS")), ,
999^99))), " ", "."), ";"))
to compensate for space separated values:
=ARRAYFORMULA(SUBSTITUTE(SPLIT(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(SUBSTITUTE(
IMPORTDATA("https://drive.google.com/uc?export=download&id=1hosZrfgrKnJJgXkgmPZSKdFoYV_AxKJS"),
" ", "♠")), , 999^99))), " ", "."), ";"), "♠", " "))
I would like to use a formula to capitalize just the first letter of an array of words. Sometimes the array might have just 1 word, and sometimes 2, 3, 4 or more words. The source is dynamic, so I need my formula to be flexible. I know about Proper(text), but that capitalizes every word.
For example, in cell A1 I might have the text "aidan is a good boy,"
or I might just have "hi,"
or maybe it will say, "drive in your own lane please!"
My formula over in B1 needs a result of "Aidan is a good boy,"; "Hi,"; or "Drive in your own lane please!"
I wish I could say, B1: =Proper(index(split(M1, " "), 1)) & " " & lower(index(split(M1, " "), *everything except 1*)), but I don't know how to fill in the *everything except 1* part of the formula.
Please try:
=REPLACE(A1,1,1,UPPER(left(A1)))
I have a table using Google Sheets. It has three columns that will always have a null value or a specific value for that column. Each line will have one, two, or three values; it will never have three null values on one line. In the fourth column, I want an ArrayFormula that will combine those values and separate the values with a comma if there is more than one.
Here is a photo of what I am trying to accomplish.
I've tried several ideas so far and this formula is the closest I've gotten so far but it's still not quite working correctly; I think it is treating each column as an array before joining rather than doing the function line by line. I'm using the LEN function rather than A2="" or ISBLANK(A2) because columns A-C are ArrayFormulas as well. I realize this probably isn't the most efficient formula to use but I think it covers every possibility. I'm definitely open to other ideas as well.
={"Focus";
ArayFormula(
IFS(
$A$2:$A="", "",
(LEN(A2:A)>0 & LEN(B2:B)>0 & LEN(C2:C)>0), TEXTJOIN(", ", TRUE, A2:A, B2:B, C2:C),
(LEN(A2:A)>0 & LEN(B2:B)>0 & LEN(C2:C)=0), TEXTJOIN(", ", TRUE, A2:A, B2:B),
(LEN(A2:A)>0 & LEN(B2:B)=0 & LEN(C2:C)>0), TEXTJOIN(", ", TRUE, A2:A, C2:C),
(LEN(A2:A)=0 & LEN(B2:B)>0 & LEN(C2:C)>0), TEXTJOIN(", ", TRUE, B2:B, C2:C),
(LEN(A2:A)>0 & LEN(B2:B)=0 & LEN(C2:C)=0), A2:A,
(LEN(A2:A)=0 & LEN(B2:B)>0 & LEN(C2:C)=0), B2:B,
(LEN(A2:A)=0 & LEN(B2:B)=0 & LEN(C2:C)>0), C2:C
)
)
}
Is it possible to achieve this with Google Sheets?
Sample File
Please try:
=ARRAYFORMULA(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(FILTER(A2:C,ROW(A2:C)<=MAX(IF(LEN(A2:C),ROW(A2:C)*COLUMN(A2:C)^0,0)))),,2^99)))," ",", "))
Notes:
The formula will work incorrectly if some names have space inside: like "Aston Martin"
So if you have spaces, please try this:
=ARRAYFORMULA(SUBSTITUTE(
SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(FILTER(SUBSTITUTE(A2:C," ",char(9)),ROW(A2:C)<=MAX(IF(LEN(A2:C),ROW(A2:C)*COLUMN(A2:C)^0,0)))),,2^99)))," ",", "),
CHAR(9)," "))
EDIT
Noticed the shorter variant (without *COLUMN(A2:C)^0) will work:
=ARRAYFORMULA(SUBSTITUTE(
SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(FILTER(SUBSTITUTE(A2:C," ",char(9)),ROW(A2:C)<=MAX(IF(LEN(A2:C),ROW(A2:C),0)))),,2^99)))," ",", "),
CHAR(9)," "))
Notes:
I used an old trick to join strings with an array-formula. See sample file
Explanations
If you like to understand any tiered formula, the best way is to split it by parts:
Part 1. Filter the data
FILTER(any_columns,ROW(A2:C)<=MAX(IF(LEN(A2:C),ROW(A2:C)*COLUMN(A2:C)^0,0))). this is my way to limit the data range.
The range is open, means it starts from the second row (A2) and
ends in any row.
I want to get the limited array in this step to reduce work that the formula should do. This is done with a condition, if.
ROW(A2:C) must be less or equal to the max row of data.
MAX(IF(LEN(A2:C), some_rows) gives the max row.
If(len.. part checks if a cell has some text inside it.
Note some_rows part:
MAX(IF(LEN(A2:C),ROW(A2:C)*COLUMN(A2:C)^0,0)))),,2^99))).
ROW(A2:C) must be multiplied by columns, because filter formula
takes only one row into its condition. That is why I multiply by
COLUMN(A2:C)^0 which is columns with 1s. Edit. Now noticed,
that the formula works fine without *COLUMN(A2:C)^0, so it's an
overkill.
Part 2. Join the text
query formula has 3 arguments: data, query_text, and a number_of_header_rows.
data is made with a filter.
query_text is empty, which gives us equivalent to select all
("select *").
And the number of rows of a header is some big number (2^99).
This is a trick: when a query has more headers then one row,
it will join them with space.
After a union is made, transpose function will convert the result back to the column.
Part 3. Substitute and trim
The function trim deletes extra spaces.
Then we replace spaces with the delimiter: ", ". That is why the
formula needs to be modified if spaces are in strings. Correct
result: "Ford, Aston Martin". Incorrect: "Ford, Aston, Martin". But
if we previously replace spaces with some char (char(9) is Tab),
then we do not replace it in this step.