Airtable If-statement outputting NaN - if-statement

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.

Related

perform mathematical operations on a number without changing the attached text

I need a formula that can multiply or divide all the numbers in a string without changing the text attached to the numbers.
I need the numbers in the next column to automatically change according to the given mathematical operation, but the text from the original line must remain unchanged.
I've tried using a combination of REGEXMATCH and REGEXEXTRACT and by doing this I just get the result of multiplying/dividing all the numbers in the string (no text whatsoever).
I also had no success using REGEXREPLACE. I'm not even sure we can actually use it in this case, and maybe I need a different formula instead. Maybe you first need to extract the numbers, multiply them and use something like TEXTJOIN or CONCATENATE to put them together in a string with the values already changed, and is this even possible in this specific example? It's totally fine to perform the operation in several steps if needed (for example, adding SPLIT function or something like that), but the format of the raw data we need to enter and recalculate, unfortunately, cannot be modified.
A sample table for better visualisation can be seen below. Any help would be greatly appreciated!
Raw data
Operation
Desired outcome
25STR/40DEX/70FRES
*0.25
6.25STR/10DEX/17.5FRES
80VIT/30INT/50CRES
*0.75
60STR/22.5INT/37.5CRES
60VIT/20STR/45LRES
*1.25
75VIT/25STR/56.25LRES
You may try:
=byrow(index(bycol(split(A2:A,"/"),lambda(z,ifna(ifs(left(B2:B,1)="*",regexextract(z,"\d+")*mid(B2:B,2,99),left(B2:B,1)="/",round(regexextract(z,"\d+")/mid(B2:B,2,99),2))&regexextract(z,"\d+(.*)"))))),lambda(y,if(y="",,join("/",y))))

Convert text to numeral text

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

Best way to show blank cell if value if zero

=COUNTIFS(Orders!$T:$T,$B4)
is a code that gives 0 or a +ve result
I use this across 1500 cells which makes the sheet gets filled with 0s
I'd like to remove the Zeros by using the following formula
if(COUNTIFS(Orders!$T:$T,$B3,Orders!$F:$F,""&P$1&"*")=0,
"",
COUNTIFS(Orders!$T:$T,$B3,Orders!$F:$F,""&P$1&"*"))
This calculates every formula twice and increases the calculation time.
How can we do this in 1 formula where if the value is 0 - keep empty - otherwise display the answer
I suggest this cell-function:
=IFERROR(1/(1/COUNTIFS(Orders!$T:$T,$B4)))
EDIT:
I'm not sure what to add as explanation. Basically to replace the result of a complex calculation with blank cells if it results in 0, you can wrap the complex function in
IFERROR(1/(1/ ComplexFunction() ))
It works by twice taking the inverse (1/X) of the result, thus returning the original result in all cases except 0 where a DIV0 error is generated. This error is then caught by IFERROR to result in a blank cell.
The advantage of this method is that it doesn't need to calculate the complex function twice, so can give a significant speed/readability increase, and doesn't fool the output like a custom number format which can be important if this cell is used in further functions.
You only need to set the number format for your range of cells.
Go to the menu Format-->Number-->More Formats-->Custom Number Format...
In the entry area at the top, enter the following: #;-#;""
The "format" of the format string is
(positive value format) ; (negative value format) ; (zero value format)
You can apply colors or commas or anything else. See this link for details
instead of your =COUNTIFS(Orders!$T:$T,$B4) use:
=REGEXREPLACE(""&COUNTIFS(Orders!$T:$T,$B4), "^0$", )
also, to speed up things you should avoid "per row formulae" and use ArrayFormulas

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.

Nested Regexmatch Not Working on Range of Zeros and Ones

I have a sum filter formula and have nested a REGEXMATCH function within it as a condition to filter the range to be summed.
The full formula looks like:
=sum(filter(data,
region1=$AF$4,
industry=$A11,
quarter=AG$9,
REGEXMATCH(consent,"1")))
The range "consent" is just 0 or 1 for each value in the range.
When I run this function 0 is returned whereas I expect about 1,000.
The documentation for REGEXMATCH says
"This function only works with text (not numbers) as input and returns
text as output. If a number is desired as the output, try using the
VALUE function in conjunction with this function. If numbers are used
as input, convert them to text using the TEXT function."
I'm not sure what to do with that. I tried the following:
REGEXMATCH(consent,1) // no luck
REGEXMATCH(TEXT(consent),"1") // no luck
REGEXMATCH(TEXT(consent),TEXT(1)) // no luck
But, if I do this:
REGEXMATCH(consent,".*") // does work for all data in consent
How can I tell GSheets to REGEXMATCH on the range consent where it equals 1?
I think the documentation is a bit misleading, because while you can convert to text using the TEXT function (which requires a second argument that prescribes the format of the output, which is why your attempt was not working), it is probably not the easiest way to do it. Probably better would be TO_TEXT, or simply appending &"":
REGEXMATCH(TO_TEXT(consent),"1")
REGEXMATCH(consent&"","1")
That being said, is there a reason you can't just use consent=1 (in which case, you could just use consent by itself as an argument in FILTER)?