Google Sheets Converting numbers imported from a different country, switching commas with periods - google-sheets

I'm importing numbers represented with commas instead of dots, and dots instead of commas, in Google sheets, and I need to convert them: from
32.072,25 to 32072.25
-1,06 to -1.06
For now I'm doing it with two nested RegExReplace expressions
REGEXREPLACE( REGEXREPLACE( B2, "\.","" ),
",", "\." )
I believe that it could be done without nesting, as part of the same RegEx operation, but I'm not knowledgeable enough about the RegEx syntax and logic to find a way. Is it possible at all?

try:
=IF(REGEXMATCH(""&B2, "[.]"),
SUBSTITUTE(SUBSTITUTE(B2, ".", ), ",", "."), SUBSTITUTE(B2, ",", "."))
to get numeric values:
=1*IF(REGEXMATCH(""&B2, "[.]"),
SUBSTITUTE(SUBSTITUTE(B2, ".", ), ",", "."), SUBSTITUTE(B2, ",", "."))

Related

How to convert first letter of each word to upper case after skipping mentioned words in Google Sheet

I want to convert the first letter of all words in string except mentioned words. Direct "Proper" function will not work as it will capitalize all first letter string.
Example: "You can install it in a few clicks and it gives you a lot many options when it comes to changing case in Google Sheets."
I want to convert the above sentence to
"You can Install it in a Few Clicks and it Gives you a Lot Many Options when it Comes to Changing Case in Google Sheets."
ignored words: it, and, in, can, you, a, to
Thanks for your help in advance.
Vineet
Use regexreplace(), like this:
=lambda(
data, lowercaseWords,
byrow(
data,
lambda(
row,
mid(
reduce(
proper("_" & to_text(row)), lowercaseWords,
lambda(
acc, word,
regexreplace(acc, "(?i)\b" & word & "\b", word)
)
),
2, 9^9
)
)
)
)(
A2:A10,
{ "it", "and", "in", "can", "you", "a", "to" }
)
Give a try on the following formula-
=LAMBDA(x,TEXTJOIN(" ",1,INDEX(IF(ISERR(SEARCH(x,"it,and,in,can,you,a,to")),PROPER(x),x))))(FLATTEN(SPLIT(A1," ")))
For dynamic input range, try-
=MAP(A1:INDEX(A1:A,COUNTA(A1:A)),LAMBDA(lm,LAMBDA(x,TEXTJOIN(" ",1,INDEX(IF(ISERR(SEARCH(x,"it,and,in,can,you,a,to")),PROPER(x),x))))(lm)))
You can use a list of words you don't want to capitalize in a certain range you stablish with the next formula. Please change A1:A with your column or range and B1 with the cell of your expression:
=REDUCE(PROPER(B1),FILTER(A1:A,A1:A<>""),
LAMBDA(phrase,words,
REGEXREPLACE(phrase,""(?i)\b"&words&"\b",words)))
If you want you can use it as an arrayformula too for a whole column of phrases B1:B:
=ArrayFormula(REDUCE(PROPER(B1:B),FILTER(A1:A,A1:A<>""),
LAMBDA(phrase,words,
REGEXREPLACE(phrase,"(?i)\b"&words&"\b",words))))

Horizontally Concatenate Array of Columns with delimiter and ignore blank columns in google sheets [duplicate]

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

How to match all of elements of array in google sheet

I have a table, and list of indexes, I want google sheets return a list of matched value.Something like this, but i doesn't work in this case. Can you help me the correct formula that it work on Google Sheet.
=TEXTJOIN(",",TRUE,INDEX(A2:B4,N(IF(1,D2))))
Put this in E2 and copy it down
=TEXTJOIN(",", TRUE, ARRAYFORMULA(VLOOKUP(SPLIT(D2, ","), $A$2:$B$4, 2, 0)))
You can do it with a formula in one cell (no need to copy it down):
=TRANSPOSE(SPLIT(TEXTJOIN(",", FALSE, ARRAYFORMULA(IFNA(VLOOKUP(SPLIT(TEXTJOIN(",,", FALSE, $D$2:$D$5), ",", TRUE, FALSE), $A$2:$B$4, 2, 0)))), ",,", FALSE, FALSE))
What exactly this formula does, going from the inside out (from TEXTJOIN(",,", ... to TRANSPOSE(...):
First TEXTJOIN joins the Condition range (D2:D4, or more if needed) in one string.
",," (the exact string of two commas) is used as the delimiter: a comma is allowed (you already use it, means there should not be commas in column A2:A4) and two commas can be distinguished from only one.
Empty strings (cells in that case) are not to be excluded so the result will be aligned with the original data.
First SPLIT gives a list of keys to be found in A2:A4.
Empty strings are preserved, so it is possible to assemble all of this back together later using ",,". Empty strings are now the delimiters.
VLOOKUP replaces the keys (A2:A4) by the values (B2:B4)
IFNA is needed so VLOOKUP won't choke on an empty string passed as a key. An empty string will remain an empty string.
ARRAYFORMULA is effectively needed for passing a range of keys (the one from the step 2) to VLOOKUP instead of just one key.
Second TEXTJOIN assembles all those values back together.
Empty strings are preserved as they are the delimiters between two Conditions.
Because of the empty strings results for each row will be separated with ",," (two commas).
Second SPLIT is used to separate the results for each row.
Empty strings are preserved for alignment with the original data.
TRANSPOSE just rotates the result into a column.
The same in a readable form (it is valid to type a formula like this):
=TRANSPOSE(
SPLIT(
TEXTJOIN(
",",
FALSE,
ARRAYFORMULA(
IFNA(
VLOOKUP(
SPLIT(
TEXTJOIN(
",,",
FALSE,
$D$2:$D$4
),
",",
TRUE,
FALSE
),
$A$2:$B$4,
2,
0
)
)
)
),
",,",
FALSE,
FALSE
)
)

Replace comma chars within importdata function

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))), " ", "."), ";"), "♠", " "))

Arrayformula generating duplicates in Google Sheets

I seem to have an arrayformula which is generating duplicates for me.
I'll show you the code in column D and then explain the problem:
=arrayformula(
if (C1225:C$1684="A",A1225:A$1684,
if (C1225:C$1684="B",B1225:B$1684,
if (C1225:C$1684="AB",{A1225:A$1684, B1225:B$1684},""))))
If A or B, it should take the content of A or B and put it in D. So I want cell E to be blank UNLESS the content in C was "AB" - only then do I want two cells populated with the data from A and B.
At the moment it's putting out A twice.
For No One|No Reply|ab|For No One|No Reply
Across The Universe (Let It Be Naked...)|The End|a|Across The Universe (Let It Be Naked...)|Across The Universe (Let It Be Naked...)
All You Need Is Love|Twist And Shout|b|Twist And Shout|Twist And Shout
So the first row is OK, but the second two are generating unwanted duplicates.
The problem you are experiencing is because the ARRAYFORMULA is making all responses an Array of 2 items. Since the end result has this size, all results must have the same size.
Try this, changing the ranges to match your needs as well as the 10:
=arrayformula(
if (C2:C$11="A",{A2:A$11, transpose(split(rept(", ", 10), ",", TRUE))},
if (C2:C$11="B",{B2:B$11, transpose(split(rept(", ", 10), ",", TRUE))},
if (C2:C$11="AB",{A2:A$11, B2:B$11},))))
The rept(", ", 10) portion creates a text string which is ", " repeated 10 times, or ", , , , , , , , , , "
Split() then splits this into an entry for each comma, removing the comma, so a series of spaces in this case. The TRUE tells Split to do this for every occurrence of the comma, so it becomes:
split(", , , , , , , , , , ", ",", TRUE)
I then use transpose () to change this into rows instead of columns. This needs to be the same number of rows as the other items in the array I am creating using the brackets so I basically get:
{A2:A$10, [Make_Blank_Entries_For_Each_Row]}
So if I did my math correctly, you should use:
=arrayformula(
if (C1225:C$1684="A",{A1225:A$1684, transpose(split(rept(", ", 460), ",", TRUE))},
if (C1225:C$11="B",{B1225:B$1684, transpose(split(rept(", ", 460), ",", TRUE))},
if (C1225:C$11="AB",{A1225:A$1684, B2:B$11},))))

Resources