I need to sum all the numbers in a string, in the string there won't be any letters only numbers. The cell contains 112121.
I tried using SUM and CASE with the QUERY Function, but CASE is not supported.
Example: 1121 = 5.
=SUMPRODUCT(REGEXEXTRACT(TO_TEXT(A1), REPT("(.)", LEN(A1))))
=INDEX(QUERY(,"SELECT "®EXREPLACE(TO_TEXT(A1),"\B","+")),2)
Convert A1 TO_TEXT
Change All non Boundary to + using REGEXREPLACE
Query's Select can accept math strings and perform calculations
INDEX to remove headers
Related
I'm struggling with writing the proper syntax for this formula in Google Sheets. In one sheet called Game Log, in the H column I have data that can be a range of names (1 - 10 names per row). I'm trying to construct a COUNTIF statement that would search for the name in all the rows for that column. There can be several other names in the same column so I need to use the wildcard * to find any occurrence of the name in each row. So for example, the current code below would count all occurrence of Adam in the rows.
=COUNTIF('Game Log'!H3:H102, "*Adam*")
What I would like to do is replace the hard codes "Adam" with a cell reference (in this case B2). Is it possible to combine that cell reference with the wild card? The know the code below doesn't work (as it would return text counting occurrences of B2), but is something like this possible?
=COUNTIF('Game Log'!H3:H102, "*B2*")
Have you tried something like this?
=COUNTIF('Game Log'!H3:H102, "*" & B2 & "*")
That ought to look for any string value, followed by the cell value, followed again by any string value. It's essentially just performing separate checks, in sequence, which allows you to search for different value types (in this case string wildcard + cell value + string wildcard).
Sample
Code:
=ArrayFormula((VLOOKUP(QUERY(UNIQUE(RANDBETWEEN(ROW(INDIRECT("A1:A"&COUNTA(A:A)*10))^0;COUNTA(A:A)));"limit 4");{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A;A:A<>"")};2;0)))
I'm trying but got this error,
test 1
Can anyone tell what's wrong? To make my code
to work as in the first picture
error in #REF!
VLOOKUP evaluates outside the range bounds.
im try change code
=ArrayFormula((VLOOKUP(QUERY(UNIQUE(RANDBETWEEN(ROW(INDIRECT("A1:A"&COUNTA(A:A)*10))^0,COUNTA(A:A))),"limit 4"),{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A,A:A<>"")},1,0)))
but number
solution for that?
=ARRAYFORMULA(VLOOKUP(FLOOR(RANDARRAY(5)*COUNTA(A2:A)),{SEQUENCE(COUNTA(A2:A),1,0),A2:INDEX(A2:A,COUNTA(A2:A))},2))
Create 5 random integers using RANDARRAY between 0(inclusive) and number of entries in A2:A(i.e., COUNTA)(exclusive).
Create a artificial side by side array({arr1,arr2}) of SEQUENCE of numbers (from 0) and actual values in A2:A
VLOOKUP the random integers in the created artificial array to give random values in A:A
If you're in locales that use comma as decimal separators, The artificial array should be created using \ instead of ,({arr1\arr2}).
=ARRAYFORMULA(VLOOKUP(FLOOR(RANDARRAY(5)*COUNTA(A2:A));{SEQUENCE(COUNTA(A2:A);1;0)\A2:INDEX(A2:A;COUNTA(A2:A))};2))
On the first formula
{ROW(INDIRECT("A1:A"&COUNTA(A:A)));FILTER(A:A;A:A<>"")}
replace the semicolon ; between INDIRECT() and FILTER() by a backslash \ as using a semicolon appends the results of FILTER to the results of INDIRECT but you are looking to put the results of each function on their own column. Please note that this formula is using semicolons as argument separator.
On the second formula replace the semicolon ; between INDIRECT() and FILTER() by a comma , (and replace the third argument of VLOOKUP, 1, by 2. Please note that this formula is using commas as argument separators.
Explanation
Commas are used as argument separator on spreadsheets that use dot as decimal separator (=SUM(1,2,3)) but also use commas as columns separator on arrays ({"a","b"})
Semicolons are used as argument separator on spreadsheets that use comma as decimal separator (=SUM(1;2;3)). On these spreadsheets, backslashes are used as columns separator on arrays ({"a"\"b"});
References
Using arrays in Google Sheets
I have a list of IDs like this :
40316C1
40316433D112
4316C1
4Z2
40316B2
40310
I would like to return the IDs like this:
40316
40316433
4316
4
40316
40310
Basically, from the first alphabet Character, Trim or Split the rest on the right.
Can I do this in Google Sheets?
You can do it with REGEXEXTRACT
Sample:
=REGEXEXTRACT(A1,"\d{1,20}")
This formula will evaluate the first 20 characters of the IDS (you can change 20 to ahigher number if necessary`
\d means that the formula will extract only numbers from the IDs - until it finds the first non-number.
UPDATE:
The case of no text characters existing in the cell can be caught with =IFERROR
=IFERROR(REGEXEXTRACT(A5,"\d{1,20}"),A5)+0
How do I remove non-numerical characters from a filter in Google Sheets?
I have a function that spits out matching phone numbers into up to 3 subsequent columns. I would like to eliminate non-number characters and a prevailing 1 if there is one, possibly using Regex.
=array_constrain(transpose(filter(People!H:H,People!B:B=A10)),1,3)
=ARRAYFORMULA(IFERROR(REGEXREPLACE(TO_TEXT(A1:A), "\D+|^1", "")))
In Google Sheets, I have this formula:
=ARRAYFORMULA( VLOOKUP( SPLIT(F2,", "), A2:B8, 2, FALSE) )
The intent is to take the comma-delimited string in cell F2 and find all values associated with the pieces. This works correctly, except when one of the pieces of the string looks like a number. For example, if F2 has the text a, 1.2, 1.2.3 then VLOOKUP will look for a as a string, and for 1.2.3 as a string, but will look for 1.2 as a number.
How can I coerce the result of SPLIT so that each piece remains a string?
I have a public copy of a test spreadsheet viewable here:
https://docs.google.com/spreadsheets/d/115WmV0vfXfaRgT0fVifJo86od3irZQy5gB3l-g6c7Ts/edit?usp=sharing
As background information, VLOOKUP treats strings and numbers differently. For example, given this table (where the formulae are shown for the first column):
A B
1 ="1.2" STR
2 =1.2 NUM
4 =VLOOKUP("1.2",A1:B2,2,0)
5 =VLOOKUP(1.2,A1:B2,2,0)
...the value shown in A4 will be "STR", and the value shown in A5 will be "NUM".
You can CONCAT a number with an empty string to convert it into its equivalent string representation.
CONCAT(1.2,"") yields "1.2"
To do this for every value, you must wrap the CONCAT() call in ARRAYFORMULA():
=ARRAYFORMULA(CONCAT(SPLIT(F2,", "),""))
The final formula thus becomes:
=TRANSPOSE(ARRAYFORMULA(VLOOKUP(ARRAYFORMULA(CONCAT(SPLIT(F2,", "),"")),A2:B8,2,FALSE)))