importxml converting string to int - google-sheets

After many hours I finally figured out how to import data from <span>...
Yet right now I've hit next wall and I can't figure out what can help me in this situation.
After using:
=IMPORTXML("https://www.bodypak.pl/pl/aminokwasy/5890-6pak-nutrition-bcaa-pak-400g.html";"//span[#id='our_price_display']")
As result, we have 79,00 PLN, yet that is String and I can't figure out how to convert it to INT
For making everything easier cell where I'm importing data I will mark as #XML =Value('#XML')
don't work, same implemented formatting.
I also tried to export the result to another cell and format another cell but that didn't work either.
=LEFT(#XML,LEN(#XML)-3) leave me with 79,00 but still I can't convert it to Int.
And I'm quite stuck right now.

You can use the function split like this: split(str, separator, 0) and take the first item of the resulting array with
=index(split(arr,","),0,1)
All together:
=index(split(split(IMPORTXML("https://www.bodypak.pl/pl/aminokwasy/5890-6pak-nutrition-bcaa-pak-400g.html","//span[#id='our_price_display']")," "),","),0,1)
The formula above truncates the string at the ",". If you want to actually convert to integer, use int() after replacing the comma with a ".":
=int(value(substitute(split(IMPORTXML("https://www.bodypak.pl/pl/aminokwasy/5890-6pak-nutrition-bcaa-pak-400g.html","//span[#id='our_price_display']")," "),",",".")))

Related

Get first Unicode character in Google Sheet

I want to get the first character from a string in a cell.
"Left" function seemed to worked fine, but it returned questions for emoji.
To extract the first one:
=REGEXEXTRACT(A1,"^.")
Unicode of first value:
=UNICODE(REGEXEXTRACT(A1,"^."))
For me the solution were to use
=char(code(A1))
code - returns the first char unicode value and then I convert it back.

Insert Dynamic Value in URL from a Cell in Google Sheet

I am trying to build a URL in a cell (google sheets) which will get some of its values from different cells. I have tried using all different ways I can think of like concatenate, Join, & etc but the problem is that the URL has some curly brackets and " as a requirement and that breaks the formula:
URL Example
https://katang.io/?t_pid=1&t_extra={"Source":"stackoverflow","Type":"email","Stategy":"banner"}
So I need "Source":"stackoverflow" to be dynamic
so for example "Source":"Get Value from Cell A1"
Any Help or guidance will be much appreciated
Things to note:
"" makes a literal " character in a string, so you'll have to double up every one.
The & is the concatenation operator in a formula, so you can use that to get values outside of your string.
Therefore, this formula should work:
="https://katang.io/?t_pid=1&t_extra={""Source"":"""&A1&""",""Type"":""email"",""Stategy"":""banner""}"

Replacing empty string cells with specific value

as you can see I have a database in SPSS and I encountered a problem where one of the columns has empty cells. Now the problem is that the type of data in that column is string. If it was numeric/integer there are tons of videos showing how to do it but none for string cells. I want to fill the empty string cells with the word "null" or "none" but I can't find a way to do it. Help!
You can use the following syntax:
IF V13 = '' V13 = 'Null'.
EXECUTE.
This syntax translates to something like: "If V13 is blank, make V13 equal to the string value 'Null'.
Just run the below syntax:
DO REPEAT S=V13 V16.
IF S="" S="none"
END REPEAT.
EXECUTE.
Store in S all your string variables. only V13 and V16 are visible on screen, so my example is built around them. But you can put as many as you need.

Google spreadsheet, passing parameter

Okay, I'm an huge noob with that kind of stuff, and I don't really know where to begin with. Google help is somehow not enough :/.
I want to make a conditionnal count on a single column :
COUNTIF(A1:A10, "3")
It will return the number of 3 in the cells from A1 to A10. Now the problem is, there can be multiples values in each cell formatted like this : "1; 3; 5". I can easily match this using regex :
B1 = REGEXEXTRACT(A1,"3")
Then repeat and sum on the second column. Now, how can I do this using a single formula?
COUNTIF(A1:A10, REGEXEXTRACT(A1:A10,"3"))
This doesn't work because regexextract take as an input a single cell. I would like to tell it to use the same cell than in the countif, but I have no clue on how to achieve this.
you can have regextract working on an array. E.g.:
=ArrayFormula(sum(--regexmatch(A2:A&"", "3")))
should count all threes (either single or in cells with multiple values), but in case you have multiple threes in one cell, you may need to use something like this:
=ARRAYFORMULA(sum(len(A:A)-len(SUBSTITUTE(A:A,"3","")))/len("3"))
This should work:
=COUNTIF(SPLIT(JOIN(";",A:A),";"),"3")

Countif with len in Google Spreadsheet

I have a column XXX like this :
XXX
A
Aruin
Avolyn
B
Batracia
Buna
...
I would like to count a cell only if the string in the cell has a length > 1.
How to do that?
I'm trying :
COUNTIF(XXX1:XXX30, LEN(...) > 1)
But what should I write instead of ... ?
Thank you in advance.
For ranges that contain strings, I have used a formula like below, which counts any value that starts with one character (the ?) followed by 0 or more characters (the *). I haven't tested on ranges that contain numbers.
=COUNTIF(range,"=?*")
To do this in one cell, without needing to create a separate column or use arrayformula{}, you can use sumproduct.
=SUMPRODUCT(LEN(XXX1:XXX30)>1)
If you have an array of True/False values then you can use -- to force them to be converted to numeric values like this:
=SUMPRODUCT(--(LEN(XXX1:XXX30)>1))
Credit to #greg who posted this in the comments - I think it is arguably the best answer and should be displayed as such. Sumproduct is a powerful function that can often to be used to get around shortcomings in countif type formulae.
Create another list using an =ARRAYFORMULA(len(XXX1:XXX30)>1) and then do a COUNTIF based on that new list: =countif(XXY1:XXY30,true()).
A simple formula that works for my needs is =ROWS(FILTER(range,LEN(range)>X))
The Google Sheets criteria syntax seems inconsistent, because the expression that works fine with FILTER() gives an erroneous zero result with COUNTIF().
Here's a demo worksheet
Another approach is to use the QUERY function.
This way you can write a simple SQL like statement to achieve this.
For example:
=QUERY(XXX1:XXX30,"SELECT COUNT(X) WHERE X MATCHES '.{1,}'")
To explain the MATCHES criteria:
It is a regex that matches every cell that contains 1 or more characters.
The . operator matches any character.
The {1,} qualifies that you only want to match cells that have at 1 or more characters in them.
Here is a link to another SO question that describes this method.

Resources