How can I SUM alphanumeric values in Google Sheets? - google-sheets

It's not the best system but I've been using ImportXML to pull in YouTube view counts for my videos so I can keep track. I knew at some point YouTube would make a front end change that would break this. So now recently instead of just the number inside of the DIV I am referencing they are always showing the word "views". So here's what I'm using now
=IMPORTXML("https://www.youtube.com/watch?v=qXnr03IIPTI","//div[#class='watch-view-count']")
This will output "300,000 views" (or whatever the current view count is)
Before they added the word "views" in this DIV I was able to add up this column. So I added another column to strip out the text.
(where G7 is the cell containing the above value)
=SUBSTITUTE(G7, "views", "")
I thought for sure I would then be able to run a SUM on this column but alas the SUM is 0. I believe this is something Excel would be able to deal with.
Any ideas here?
Bonus points if you watch the video :)

If the result is in G7, use formula:
=JOIN("",REGEXEXTRACT(G7,"([0-9]+),([0-9]+),?([0-9]+)?"))*1
it will convert string "300,000 views" into number. It'll handle bigger numbers, like: 1,368,142 views. This formula replaces commas because in some countries comma is used as sepatator integer and decimal part of number.

You can convert it to a value:
=VALUE(REGEXREPLACE(IMPORTXML("https://www.youtube.com/watch?v=qXnr03IIPTI","//div[#class='watch-view-count']")," views",""))
or
=VALUE(REGEXREPLACE(IMPORTXML("https://www.youtube.com/watch?v=qXnr03IIPTI","//div[#class='watch-view-count']"),"[, views]",""))
if you really want the commas etc, wrap the final amount back into a text at the very end if you want such as =TEXT("FINAL SUM","#,#")

Try this:
=REGEXEXTRACT(IMPORTXML("https://www.youtube.com/watch?v=qXnr03IIPTI","//div[#class='watch-view-count']"), "[0-9]*\,[0-9]+[0-9]+")

Related

GoogleSheets - bringing back last "n" characters that are uppercase only

I have data that brings back a name plus the ticker code. I need to extract the ticker code only into google sheets.
using: =IMPORTXML("https://www.coingecko.com/?page=5","//tr") I bring back 100 coins but the first column is for example
Dogecoin9DOGE
or
Ethereum2ETH
or
Ethereum ClassicETC
I would like to create a column that simply has DOGE or ETH or ETC, anyone know of a way to manipulate the 1st column to get to that?
Thanks
the webpage looks like it is 2 separate columns but the extract does not work that way. I was trying to think of a way to count the uppercase values and then maybe use a RIGHT(len(uppercasevalues)) but not sure how to get there.
You can use REGEXEXTRACT.
=REGEXEXTRACT(A1,"[A-Z]+$")

Combining REGEXEXTRACT and SUBSTITUTE in Google Sheets Formula

I'm extracting text from filename cells into separate metadata field cells. So far I have done this successfully using the REGEXTRACT formula, as seen below.
=REGEXEXTRACT(A1, "TILEABLE|ROOM|MAIN|FLOORSHOT|SWATCH|ANGLED")
However some metadata fields that include multiple words require that a space or other character be placed between words. I'm trying to figure out how to use SUBSTITUTE or REPLACE in conjunction with REGEXTRACT to find a phrase and replace it with a version with something different. Ex. Replace "TOPDOWN" with "Top Down" or replace "1TO1" with "1-to-1).
Depending on your purpose one formula might be better than other. If you want to list in a column the substituted values of this string you could chain the number of phrases you want using SUBSTITUTE and REGEXTRACT.
This will return all the phrases you are looking for and substitute them to then use the formula TRANSPOSE to take this range and display it in a columns (as it normally would be displayed in a row and only a single value). This is a simple example:
=TRANSPOSE({SUBSTITUTE(REGEXEXTRACT(A1,"TOPDOWN"),"TOPDOWN","Top Down"),SUBSTITUTE(REGEXEXTRACT(A1,"SHIRTS"),"SHIRTS","Shirts1")})
try:
=SUBSTITUTE(SUBSTITUTE(REGEXEXTRACT(A1,
"TOPDOWN|1TO1|TILEABLE|ROOM|MAIN|FLOORSHOT|SWATCH|ANGLED"),
"TOPDOWN", "Top Down"),
"1TO1", "1-to-1")

How to transpose rows into columns of contact details without mixing them up? (Google Sheets)

I have a data set of contact details where the emails and their names are scattered in rows, I would like to list them in 2 nice columns. I've tried using "paste special" and use this code below, but none of them worked.
This is how it looks like:
I've tried this code, but it only applies to one row, whereas I want to apply it to all rows and columns.
=transpose(A2:R2)
and
=transpose (A2:R300)
Both don't work. I hope somebody can help me with this, I'd really appreciate it. Thanks in advance!
It looks that you are using the wrong terms so you are using the wrong functions.
Apparently you have a cell with data separated by spaces and break lines and you want to have each email and name on it's own cell, having emails on one column and names on the next column.
One way to achieve that, first replace the separating spaces by using a character like | and the break lines by another different character like $.
Note: Some people use Unicode characters that are very unlikely to appear like ♦, ❤.
To do the above for break lines you could use FIND and REPLACE (Ctrl + H) or function formulas like REGEXREPLACE, SUBSTITUTE, and maybe others. As there are spaces used both as word separators and values separators, FIND and REPLACE can't be used easily. For a single cell, maybe the easier way is to insert the name/email separator manually.
Then separate the cell data. To do this you could use a formula function like SPLIT or Data > Separate values into columns.
Another way is by using Google Apps Script and JavaScript string handling methods but basically the algorithm is the same.
Related
How to split this complex string into 3 columns and 50 rows using Google sheet script
Google Apps Script: Create new rows for cells that contain commas
Google Sheets: string to columns and rows

How to count NUMBERS from google sheets when there is also a word there which doesn't need counting

Can't find a function which allows me to count the numbers, add them up and then paste it onto the first row. As there are also words there, for description of what is being counted then I've not yet found a way to count numbers without the words becoming a source of error.
Already tried the use of different functions
Fix my table so i can start counting how many things i do in a day/year
How it should look like
Finished code in the sheet, big thanks to pnuts
Try something like:
=sum(ArrayFormula(iferror(1*REGEXEXTRACT(A1:A4,"\d+"),0)))
and if you have cells in the selected range that are Number format and want those included in the addition, add those as well as a separate clause (ie append +sum(A1:A4)).

Extract Values from Cells > Sum the Values > Multiply the Values

I have two sheets in my Google spreadsheet, "input" and "output".
On my "input" sheet I have multiple values,
which always have a certain letter in front of them.
On the other sheet "output" I want to add all values together for each letter
and then be able to multiply this result with another value.
The values sometimes are whole numbers, other times they hav decimal places.
I tried the following functions to extract only the number without the letter,
but then the extracted value was not a number that I could continue to use for other math functions such as multiplications.
=REGEXEXTRACT(XX;"[0-9]+")
=REGEXEXTRACT(XX;"[0-9]*\.[0-9]+")
=REGEXEXTRACT(XX; "\d+")
=SUM(SPLIT(XX;CONCATENATE(SPLIT(XX;".0123456789"))))^
If I tried to use "=VALUE(XX)" I got a weird number.
Also this formulars are only for one cell,
but I want the formula to work on the whole "input" sheet.
Therefor it must be used in combination with something like
=SUMIF('input'!A:Z; "XXXX"; 'input'!A:Z)
...at least this is my best guess.
I linked a sample sheet below, can you help me out guys?
Many thanks in advance!
Google Spreadsheet Test
For getting the sum of the cells which have letter "E" at the beginning, try the following formula:
=sum(arrayformula(iferror(regexextract(input!A1:H100,"E ([\d.+]*)")*1)))

Resources