How to create result from multiple IF results neatly in Google Sheets - regex

I want to combine multiple results of if statement into a form of a sentence.
Code:
=CONCAT("Fail column", IF($T3="No", " T", "")& IF($U3="No", ", U", "") & IF($W3<7, ", W", "") & IF($X3>3, ", X", "") & IF($AE3="No", ", AE", "") & IF($AF3="No", ", AF", ""))
Sample data :
If the first statement returns blank, the next statement would not show the comma at the beginning. And let say all pass, they would be shown as "Yes".
My expected output can be:
Fail column T, U, W, X, AE, AF
Fail column U, W, X, AE, AF
Fail column T
Fail column W, X
Yes

I'm thinking you could try:
Formula in R3:
=IF(OR(T3="No",U3="No",W3<7,X3>3,AE3="No",AF3="No"),"Fail column: "&TEXTJOIN(", ",TRUE,IF(T3="No","T",""),IF(U3="No","U",""),IF(W3<7,"W",""),IF(X3>3,"X",""),IF(AE3="No","AE",""),IF(AF3="No","AF","")),"Yes")
The key here is TEXTJOIN instead of CONCAT to exclude any empty values from the concatenated string.
Note: Excel and Google Spreadsheets are two different apps and the functions are not always exchangeable. Your question's title suggests that you are actually using Excel, however your tags include GS.

correct formula would be:
=ARRAYFORMULA(REGEXREPLACE(IF(
(T3:T="yes")*(U3:U="yes")*((W3:W<7)*(W3:W<>""))*(X3:X>3)*(AE3:AE="yes")*(AF3:AF="yes"),
"yes", "Fail column: "&
IF(T3:T="no", "T, ", )&
IF(U3:U="no", "U, ", )&
iF(W3:W>=7, "W, ", )&
IF((X3:X<=3)*(X3:X<>""), "X, ", )&
IF(AE3:AE="no", "AE, ", )&
IF(AF3:AF="no", "AF, ", )), ", $|Fail column: $", ))

Related

Having a problem with IF function argument in Spreadsheet

I'm trying to make this description generator, and I can't seem to make the first part work for one of the IF arguments as it does with the rest. It only checks the logical expression but doesn't bring the rest of the text body in the cell joined with & as it does in the case of the other IF arguments I have there linked one after the other. This example should make more sense.
try:
=INDEX(REGEXREPLACE(SUBSTITUTE(SUBSTITUTE(TRIM(FLATTEN(QUERY(TRANSPOSE(IF(IFERROR(
SPLIT(B1:B, CHAR(10)))="",,REGEXREPLACE({"", SEQUENCE(1, 100)}&". "&IFNA(VLOOKUP(
TRIM(SPLIT(B1:B, CHAR(10))),
{"ck", "click >";
"box", "select box";
"scd", "scroll down >"}, 2, 0),
SPLIT(B1:B, CHAR(10))), " ", CHAR(13)))),,9^9))),
" ", CHAR(10)), CHAR(13), " "), "^\. !?", ))
demo sheet
The first If statement encloses all the rest of the formula so if the regex matches "ck" the condition is satisfied, you get "click >" but nothing else happens. I think you can just move the final bracket so it is just after "select " like this:
=IF(REGEXMATCH(B4, "ck"),"click >",IF(REGEXMATCH(B4, "scd"),"scroll down > ",IF(REGEXMATCH(B4, "!"),"","select "))) & ARRAYFORMULA(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(TEXTJOIN(CHAR(10), 1, IF(REGEXMATCH(""&
SPLIT(B4, CHAR(10)), "^>.*"),
SPLIT(B4, CHAR(10)), TRANSPOSE(MMULT(TRANSPOSE(TRANSPOSE((SEQUENCE(1, COLUMNS(
SPLIT(B4, CHAR(10))))<=SEQUENCE(COLUMNS(
SPLIT(B4, CHAR(10))), 1, 0))*NOT(REGEXMATCH(
SPLIT(B4, CHAR(10)), "^>.+")))), TRANSPOSE(SIGN(NOT(REGEXMATCH(
SPLIT(B4, CHAR(10)), "^>.+"))))))&". "&
SPLIT(B4, CHAR(10)))), "^0. ", ),"scd",""),"ck",""),"!",""))

Return true/false on [strings in a cell] being found in [strings in another cell]?

Cell A1 contains multiple strings, eg "CAT DOG RAT GNU";
Cell B1 contains multiple strings, eg "RAT CAT";
How can I run a test (using formula in C1) to find if all the strings in B1 are present in cell A1?
Returning true/false would be good
Strings not necessarily in the same order, as example above
The number of items can vary
Multiple instances not a problem, so long as they're there
But returns true only if all items in cell B1 are present in cell A1.
So far I've tried transposed-split arrays with vlookups and matches, counts, etc, but nothing working for me. (And maybe regex won't do it as can't loop for each string?)
you can try:
=ARRAYFORMULA(IF(PRODUCT(N(NOT(ISNA(REGEXEXTRACT(SPLIT(B1, " "),
SUBSTITUTE(A1, " ", "|"))))))=1, TRUE))
for more precision you can do:
=ARRAYFORMULA(IF(PRODUCT(N(NOT(ISNA(REGEXEXTRACT(SPLIT(B1, " "),
"^"&SUBSTITUTE(A1, " ", "$|^")&"$")))))=1, TRUE))
then for case insensivity:
=ARRAYFORMULA(IF(PRODUCT(N(NOT(ISNA(REGEXEXTRACT(SPLIT(LOWER(B1), " "),
"^"&SUBSTITUTE(LOWER(A1), " ", "$|^")&"$")))))=1, TRUE))
and true ArrayFormula would be:
=ARRAYFORMULA(IF((A1:A<>"")*(B1:B<>""), IF(REGEXMATCH(TRANSPOSE(QUERY(TRANSPOSE(IFERROR(
REGEXMATCH(IF(SPLIT(B1:B, " ")<>"", SPLIT(LOWER(B1:B), " "), 0),
"^"&SUBSTITUTE(LOWER(A1:A), " ", "$|^")&"$"))),,999^99)), "FALSE"), FALSE, TRUE), ))

proper IF statement issue causing parse error

I am searching for a formula to combine three things. To capture the value of Cell A into cell B. If it has has a number then it should capture that number. If the value of cell A1 is - then it should change to blank in cell B1 and if it has a blank cell in A1 Then it should be blank in B1.
I have tried the formula in google sheet with IF, And OR combining but it is giving an error.
=if(OR(A1="-"," "),(A1=" ", " "))
=if(And(A1="-"," "),(A1=" ", " "))
=IF(A1="-"," ",IF(A1="","",IF(A1=" "," ")))
The expected results are giving an error or it gives the answer as false.
You should take a look at IF documentation to understand it better, but the main thing here is to remember that IF is IF(logical_expression, value_if_true, value_if_false)
The best option here would be to go with player0 solution, because it covers up almost every case: =IF(ISNUMBER(A1), A1, )
But just to help you out on understanding what was wrong with your formulas, even though those solutions don't check if A1 is a number:
=if(OR(A1="-"," "),(A1=" ", " "))
The correct way would be: =if( OR(A1="-",A1=" "), " ", A1)
=if(And(A1="-"," "),(A1=" ", " "))
This one is actually conceptually wrong, because you want to check if A1 = "-" AND A1 =" ", which is impossible and will never be true, because a cell can't be equal to "-" and " " at the same time.
=IF(A1="-"," ",IF(A1="","",IF(A1=" "," ")))
The correct way would be: =IF(A1="-"," ",IF(A1="","",IF(A1=" "," ",A1)))
that is not how you should use IF function.
If the value of cell A1 is - then it should change to blank in cell B1 and if it has blank cell in A1 Then it should be blank in B1
which could be solved like this in B1 cell:
=IF(ISNUMBER(A1), A1, )
and arrayformula of that would be:
=ARRAYFORMULA(IF(ISNUMBER(A1:A*1), A1:A, ))

Reference text from cell and return remaining text to other cell

So my question is... I have 2 columns, A and B. In B I want to read the text from A (which has a list of texts: eg. Normal Car, Lorry, Sports Car, Bike) and I would type some text specified from the list in 'A' (eg. Bike) and in B would be the text that is left from that list from 'A' (So meaning "Normal Car", "Lorry" and "Sports Car" would be shown in 'B')
How do I do that?
This is the spreadsheet example:
https://docs.google.com/spreadsheets/d/16o75-R-U3zY0vajg1pO0N7-t9uGCtt_B2QiZLW_sXUM/edit#gid=0
Here are all the words that will be used: Lyrics, Visualizer, Bass Boost, 8D, Nightcore, Image Only
What I want to achieve is if I fill one or more of the words in Column A, then all the rest of the words will be filled up in B automatically. I left them filled up already so you can see the example. Thanks.
for one word:
=ARRAYFORMULA(REGEXREPLACE(TRIM(IF(LEN(A1:A),
REGEXREPLACE("Lyrics, Visualizer, Bass Boost, 8D, Nightcore, Image Only,",
A1:A&",", ), )), ",$", ))
for multiple words:
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(A1:A), SUBSTITUTE(
REGEXREPLACE({"Lyrics", "Visualizer", "Bass Boost", "8D", "Nightcore", "Image Only"},
REGEXREPLACE(A1:A, ", ", "|"), ), " ", "♦"), )),,999^99))), " ", ", "), "♦", " "))
I would type some text specified from the list in 'A' (eg. Bike) and in B would be the text that is left from that list from
try like this:
=ARRAYFORMULA(REGEXREPLACE(TRIM(REGEXEXTRACT(A1:A, "(.*)"&B1:B)), ",$", ))

R: gsub with fixed=T or F and special cases

Building on top of two questions I previously asked:
R: How to prevent memory overflow when using mgsub in vector mode?
gsub speed vs pattern length
I do like suggestions on usage of fixed=TRUE by #Tyler as it speeds up calculations significantly. However, it's not always applicable. I need to substitute, say, caps as a stand-alone word w/ or w/o punctuation that surrounds it. A priori it's not know what can follow or precede the word, but it must be any of regular punctuation signs (, . ! - + etc). It cannot be a number or a letter. Example below. capsule must stay as is.
i = "Here is the capsule, caps key, and two caps, or two caps. or even three caps-"
orig = "caps"
change = "cap"
gsub_FixedTrue <- function(i) {
i = paste0(" ", i, " ")
orig = paste0(" ", orig, " ")
change = paste0(" ", change, " ")
i = gsub(orig,change,i,fixed=TRUE)
i = gsub("^\\s|\\s$", "", i, perl=TRUE)
return(i)
}
#Second fastest, doesn't clog memory
gsub_FixedFalse <- function(i) {
i = gsub(paste0("\\b",orig,"\\b"),change,i)
return(i)
}
print(gsub_FixedTrue(i)) #wrong
print(gsub_FixedFalse(i)) #correct
Results. Second output is desired
[1] "Here is the capsule, cap key, and two caps, or two caps. or even three caps-"
[1] "Here is the capsule, cap key, and two cap, or two cap. or even three cap-"
Using parts from your previous question to test I think we can put a place holder in front of punctuation as follows, without slowing it down too much:
line <- c("one", "two one", "four phones", "and a capsule", "But here's a caps key",
"Here is the capsule, caps key, and two caps, or two caps. or even three caps-" )
e <- c("one", "two", "caps")
r <- c("ONE", "TWO", "cap")
line <- rep(line, 1700000/length(line))
line <- gsub("([[:punct:]])", " <DEL>\\1<DEL> ", line, perl=TRUE)
## Start
line2 <- paste0(" ", line, " ")
e2 <- paste0(" ", e, " ")
r2 <- paste0(" ", r, " ")
for (i in seq_along(e2)) {
line2 <- gsub(e2[i], r2[i], line2, fixed=TRUE)
}
gsub("^\\s|\\s$| <DEL>|<DEL> ", "", line2, perl=TRUE)