Convert text to numeral text - regex

I have a google spreadsheet that I am using as a quiz. The quiz takers select an option from a data validation drop down.
The cell below strips all but the first character =left(A2,1) which is a numeral value. Further below in the sheet is a cell that sums certain cells, For instance,
=Sum(A3,D3)
For some reason, the sum function does not recognize the cell as a purely numeral value, even with changing the format to number. Any ideas?

you can use SUMPRODUCT instead of SUM which is able to recognize numeric values even if they are disguised as a text string:
=SUMPRODUCT(A3:D3)
another way would be use regex like:
=ARRAYFORMULA(REGEXEXTRAXT(A3:D3, "(\d+)-")*1)

Given what is immediately above the values in Row3, that row might be redundant and the total calculated as:
=ArrayFormula(sum(0+left(A2:D2)))

Related

How to filter by Regex in LibreOffice?

I've got this string:
{"success":true,"lowest_price":"1,49€","volume":"1,132","median_price":"1,49€"}
Now I want the value for median_price being displayed in a cell. HHow can I achive this with Regex?
With regex101.com I've came to this solution:
(?<=median_price":")\d{0,4},\d{2}€
But this one does not seem to be working in LibreOffice calc.
I'd advise to discard the Euro-symbol at first since you'd probably want to retrieve a value to calculate with, a numeric value. Therefor try:
Formula in B1:
=--REGEX(A1;".*median_price"":""(\d+(?:,\d+)?)€.*";"$1")
The double unary will transform the result from the 1st capture group into a number. I then went ahead and formatted the cell to display currency (Ctrl+Shift+4).
Note: I went with a slightly different regular pattern. But go with whatever works for your data I supppose.

Find "real" formula for a formula group

I am trying to find the "real" formula of a group. For example, these are the formulas
=If(A$4>$A1,"Long","Short")
=If(B$4>$A1,"Long","Short")
=If(A$4>$A2,"Long","Short")
=If(A$4>$A$2,"Long","Short)
The forth formula is a different one. The first 3 formulas should be the same formula that is a cell fixed 4th row compare to a cell fixed at column A. The result should show 2 "real" formula. Something like this
=If($4>$A,"Long","Short")
=If($4>$A$2,"Long","Short")
How do I design a regex (or any other method) in VBA to extract that "real" formula from the "nominal" formulas?
Convert your formulas to display in R1C1 format by using File,Options,Formulas and ticking R1C1 style. In such a style your four example formulas would display (If they were entered in column 3) as
=IF(R4C[-2]>RC1,"Long","Short")
=IF(R4C[-1]>R[-1]C1,"Long","Short")
=IF(R4C[-2]>R[-1]C1,"Long","Short")
=IF(R4C[-2]>R2C1,"Long","Short")
The fixed portions of the addresses don't have braces [] so if you remove the braces and their contents you get
R4C>RC1
R4C>RC1
R4C>RC1
R4C>R2C1
and no 4 is different from the others

Airtable If-statement outputting NaN

I'm using an If-statement to assign integers to strings from another cell. This seems to be working, but if I reference these columns, I'm getting a NaN value. This is my formula below. I tried adding INT() around the output values, but that seemed to break everything. Am I missing something?
IF(FIND('1',{Functional response}),-4,
IF(FIND('2',{Functional response}),-2,
IF(FIND('3',{Functional response}),0,
IF(FIND('4',{Functional response}),2,
IF(FIND('5',{Functional response}),4,"")))))
Assuming Functional response can only store a number 1 to 5 as a string a simple option in excel would be to first convert the string to a number and then use the choose function to assign a value. this works as the numbers are are sequential integers. Assuming Cell K2 has the value of Functional response, your formula could be:
=CHOOSE(--K2,-4,-2,0,2,4)
=CHOOSE(K2+0,-4,-2,0,2,4)
=CHOOSE(K2-0,-4,-2,0,2,4)
=CHOOSE(K2*1,-4,-2,0,2,4)
=CHOOSE(K2/1,-4,-2,0,2,4)
Basically sending the string of a pure number through a math operation has excel convert it to a number. By sending it through a math operation that does not change its value, you get the string as a number.
CHOOSE is like a sequential IF function Supply it with an integer as the first argument and then it will return the value from the subsequent list that matches the number. if the number you supply is greater than the number of options you will get an error.
Alternatively you could just do a straight math convertion on the number stored as a string in K2 using the following formula:
=(K2-3)*2
And as my final option, you could build a table and use VLOOKUP or INDEX/MATCH.
NOTE: If B2:B6 was stored as strings instead of numbers, K2 instead of --K2 would need to be used.

How to use numbers present as text with different unit prefixes in calculations

I have data in a spreadsheet describing amount of data transferred over a mobile network: data in one column (over 300 rows) has three possible forms:
123,45KB
123,45MB
1,23GB
How can I transform or use this data in order to sum or do other calculations on numbers properly?
Assuming your data is in column A and there are always two characters as unit ("KB", "MB" or "GB") at the end, then the formula for transforming the data to numeric could be:
=--LEFT(A2;LEN(A2)-2)*10^(IF(RIGHT(A2;2)="KB";3;IF(RIGHT(A2;2)="MB";6;IF(RIGHT(A2;2)="GB";9))))
Result:
Put the formula in B2 and fill downwards as needed.
I suspected the decimal delimiter in your locale is comma. If not, please state what it is.
Also since this site is English, I have used English function names. Maybe you need to translate them into your language version.
If the decimal delimiter in your locale is not comma, then you need substituting the comma with your decimal delimiter to get a proper numeric decimal value.
For example if the decimal delimiter is dot, then:
=SUBSTITUTE(LEFT(A2,LEN(A2)-2),",",".")*10^(IF(RIGHT(A2,2)="KB",3,IF(RIGHT(A2,2)="MB",6,IF(RIGHT(A2,2)="GB",9))))
An alternative formula:
=LEFT(A1,LEN(A1)-2)*10^(3*MATCH(RIGHT(LEFT(A1,LEN(A1)-1)),{"K","M","G"},0))
Uses the position of the next to last character in an array to determine the factor.

Regular expression for a time format

I am trying to search for cells in a column containing a time in the format of 00:00 using the MATCH function. I have tried things similar to MATCH("??:??",A:A) and MATCH("?*:?*",A:A) with no luck. How can I form a regular expression of 2 digits, then a colon, then 2 digits?
Often times what is displayed to us in excel isn't the actual value. Time and Dates are one such time. Generally if you enter a time into excel 3:55 it will convert that automatically to excel's time format, which is a decimal number: 0.163194444444444, but it formats it automatically to "mm:ss" just like you entered it.
So... when you try to =MATCH() using a wildcard, you aren't going to find a hit since the value in the cell is actually that decimal number.
Instead you have to convert the value of the cells you are searching into a text format. You can do that with the =TEXT() formula. Assuming your data starts in A1 you can put in B1:
=Text(A1, "mm:ss")
Now the returned value from that formula still looks like the mm:ss format, but it's now text. The underlying value is actually 3:55. No funny business. You can now base your wild card search of "*:*" off of this column:
=Match("*:*", B1:B10, 0)
If you want to do this all in one formula you can use an Array formula (or CSE):
=Match("*:*", Text(A1:A10,"mm:ss"),0)
Using Ctrl+Shift+Enter (instead of Enter) when you enter the formula.