Using IFS and REGEXMATCH Fails - regex

I'm trying to use the following IFS statement
=IFS(REGEXMATCH(B2,"football"),"brown",REGEXMATCH(B2,"baseball"),"white")
but Google Sheets keeps saying the syntax is wrong. What is wrong with this?
Column B is a text column.
Other similar posts did not work for me.

The formula works fine.
You probably need to change it (depending on your locale) to:
=IFS(REGEXMATCH(D2;"football");"brown";REGEXMATCH(D2;"baseball");"white")
Another improvement you may make is to wrap it in the IFNA function
=IFNA(IFS(REGEXMATCH(D2,"football"),"brown",REGEXMATCH(D2,"baseball"),"white"),"No match")

Related

How to Keep rows of multi-line cells containing a keyword in google sheets

I'm trying to keep lines that contain the word "NOA" in a column A which has many multi-line cells as can be viewed in this Google Spreadsheet.
If "NOA" is present then, I would like to keep the line. The input and output should look like the image which I have "working" with too-many helper cells. Can this be combined into a single formula?
Theoretical Approaches:
I have been thinking about three approaches to solve this:
ARRAYFORMULA(REGEXREPLACE - couldn't get it to work
JOIN(FILTER(REGEXMATCH(TRANSPOSE - showing promise as it works in multiple steps
Using the QUERY Function - unfamiliar w/ function but wondering if this function has a fast solution
Practical attempts:
FIRST APPROACH: first I attempted using REGEXEXTRACT to extract out everything that did not have NOA in it, the Regex worked in demo but didn't work properly in sheets. I thought this might be a concise way to get the value, perhaps if my REGEX skill was better?
ARRAYFORMULA(REGEXREPLACE(A1:A7, "^(?:[^N\n]|N(?:[^O\n]|O(?:[^A\n]|$)|$)|$)+",""))
I think the Regex because overly complex, didn't work in Google or perhaps the formula could be improved, but because Google RE2 has limitations it makes it harder to do certain things.
SECOND APPROACH:
Then I came up with an alternate approach which seems to work 2 stages (with multiple helper cells) but I would like to do this with one equation.
=TRANSPOSE(split(A2,CHAR(10)))
=TEXTJOIN(CHAR(10),1,FILTER(C2:C7,REGEXMATCH(C2:C7,"NOA")))
Questions:
Can these formulas be combined and applied to the entire Column using an Index or Array?
Or perhaps, the REGEX in my first approach can be modified?
Is there a faster solution using Query?
The shared Google spreadhseet is here.
Thank you in advance for your help.
Here's one way you can do that:
=index(substitute(substitute(transpose(trim(
query(substitute(transpose(if(regexmatch(split(
filter(A2:A,A2:A<>""),char(10)),"NOA"),split(
filter(A2:A,A2:A<>""),char(10)),))," ","❄️")
,,9^9)))," ",char(10)),"❄️"," "))
First, we split the data by the newline (char 10), then we filter out the lines that don't contain NOA and finally we use a "query smush" to join everything back together.

TO_PURE_TEXT with cell referencing doesn't filter double quotes against documentation

I want to get a clean number from a string like "123.45". On using of =TO_PURE_TEXT(C10) it doesn't work for me,
against an example from the documentation. An absolute referencing doesn't help.
But, if i use no cell referencing, but direct input, like =TO_PURE_TEXT("123.45") the input is correct, as expected without quotes.
Is it a kind of bug, or do i really do something wrong? How can i get this work with the cell referencing?
all you need is:
=SUBSTITUTE(C10, """", )*1
or:
=REGEXREPLACE(C10, """", )*1
I can't speak to whether it's a bug. Does seem odd, but this should work for now:
=1*SUBSTITUTE(C10,CHAR(34),"")

Untranslatable character when extracting dates from strings

I am attempting to extract dates from a free-text field (because our process is awesome like that :\ ) and keep hitting Teradata error 6706. The regex I'm using is: REGEXP_SUBSTR(original_field,'(\d{2})\/(\d{2})\/(\d{4})',1) AS new_field. I'm unsure of the field's type HELP TABLE has a blank in the Type column for the field.
I've already tried converting using TRANSLATE(col USING LATIN_TO_UNICODE), as well as UNICODE_TO_LATIN, those both actually cause the error by themselves. A straight CAST(original_field AS VARCHAR(255)) doesn't fix the issue, though that cast does work. I've also tried stripping various special characters (new-line, carriage return, etc.) from the field before letting the REGEXP_SUBSTR take a crack at it, both by itself and with the CAST & TRANSLATEs I already mentioned.
At this point I'm not sure what the issue could be, and could use some guidance on additional options to try.
The final version that worked ended up being
, CASE
WHEN TRANSLATE_CHK(field USING LATIN_TO_UNICODE) = 0 THEN
REGEXP_SUBSTR(TRANSLATE(field USING LATIN_TO_UNICODE),'(\d{2})\/(\d{2})\/(\d{4})',1)
ELSE NULL
END AS Ref_Date
For whatever reason, using a TRIM inside the TRANSLATE seems to cause an issue. Only once I striped any and all functions from inside the TRANSLATE did the TRANSLATE, and thus the REGEXP_SUBSTR, work.

openoffice calc use contents of a cell as the formula for another

I searched for this and couldn't find how to do it. I have a cell that has an equation like: ".25 + .33" which I want displayed exactly like that. In the cell next to it, I want it to give me the result of that equation, ie, to turn that into "=.25 - .33" and show the result. I know I could do it the other way around, typing the formula out, and then using =FORMULA() and REPLACE() to remove the '=' or even use macros. But that's not what I want in this case. Is there a way to do this? I tried looking at functions like =INDIRECT() but no joy.
Given the constraints you have chosen, in a word, No.

IFERROR STATEMENT WITHIN VLOOKUP

I asked for help on another formula earlier which has lead to another head scratcher for me. I'm sure there is probably a way to use IFERROR somewhere in the formula below, but I can't seem to figure out where. I have a few columns returning #N/A that I just need to be blank.
Everything is working how it should except for the error. I have another formula feeding off of the results of this formula that I need to populate either Y or N based on the results. The #N/A is throwing some of them off.
=IF(J2="",VLOOKUP(B2,Sheet1!B:F,5,FALSE),"PICKED UP")
Just wrap it like this:
=IF(J2="",IFERROR(VLOOKUP(B2,Sheet1!B:F,5,0),"Error msg here"),"PICKED UP")
IFERROR will evaluate the first expression (here, it's the VLOOKUP) and if it returns an error, it will return the second part of the formula, which is Error msg here in this case. Change it to whatever you want to.
Also, you can use 0 to mean FALSE in excel (and 1 to mean TRUE).
=IF(J2="", IF(ISNA(VLOOKUP(B2,Sheet1!B:F,5,FALSE)), "", VLOOKUP(B2,Sheet1!B:F,5,FALSE)),"PICKED UP")