Arrayformula - Cell contains text (Google Sheets) - google-sheets

I have the formula written below. On the condition where Column E = "EPIs", there is a second condition to verify if Column G contains the string ("CC", "Hemo" or "odonto").
But that second condition is not returning correctly the 'contains the specified string' part.
It gets true for Col E = "EPIs", but false for the second cases.
How can I make it work?
=ARRAYFORMULA(
IF(B3:B="";"";
IF(M3:M="";"Verificar";
IF(M3:M="Realizado - Sem Certificado";"Verificar";
IF(M3:M="Manutenção";"Verificar";
IF(M3:M="Verificar";"Verificar";
IF(M3:M="Verificar se está ativo";"Verificar";
IF(M3:M="Não realizado";"Verificar";
IF(M3:M="Desativado";"DESATIVADO";
IF(E3:E="EPIs";
(IF(G3:G="*CC*";IF(DATE(YEAR(M3:M);MONTH(M3:M)+6;DAY(M3:M))>TODAY();IF(DATE(YEAR(M3:M);MONTH(M3:M)+4;DAY(M3:M))>TODAY();"OK";"Realizar CQ");"Vencido");
IF(G3:G="*hemo*";IF(DATE(YEAR(M3:M);MONTH(M3:M)+6;DAY(M3:M))>TODAY();IF(DATE(YEAR(M3:M);MONTH(M3:M)+4;DAY(M3:M))>TODAY();"OK";"Realizar CQ");"Vencido");
IF(G3:G="*odonto*";IF(DATE(YEAR(M3:M)+2;MONTH(M3:M);DAY(M3:M))>TODAY();IF(DATE(YEAR(M3:M)+2;MONTH(M3:M)-2;DAY(M3:M))>TODAY();"OK";"Realizar CQ");"Vencido");
IF(DATE(YEAR(M3:M)+1;MONTH(M3:M);DAY(M3:M))>TODAY();IF(DATE(YEAR(M3:M)+1;MONTH(M3:M)-2;DAY(M3:M))>TODAY();"OK";"Realizar CQ");"Vencido")
))));
IF(E3:E="Odonto Intra";IF(DATE(YEAR(M3:M)+2;MONTH(M3:M);DAY(M3:M))>TODAY();IF(DATE(YEAR(M3:M)+2;MONTH(M3:M)-2;DAY(M3:M))>TODAY();"OK";"Realizar CQ");"Vencido");
IF(DATE(YEAR(M3:M)+1;MONTH(M3:M);DAY(M3:M))>TODAY();IF(DATE(YEAR(M3:M)+1;MONTH(M3:M)-2;DAY(M3:M))>TODAY();"OK";"Realizar CQ");"Vencido") ) ))))))))))

The formula you wrote is quite a bit more convoluted than you needed it to be.
I think using EDATE() and LOOKUP() you can achieve the desired effect more easily.
=ARRAYFORMULA(IF(M3:M="";;LOOKUP(TODAY()-EDATE(M3:M;IF(REGEXMATCH(G3:G;"Hemo|CC");6;IF(REGEXMATCH(G3:G;"Odonto");24;12)));{-9^9;-60;0};{"OK";"Realizar";"Vencido"})))

Related

Force query to return nothing

I have this query for filtering a sheet by multiple criteria:
=query(A2:H,"select A,B,C,D,E,F,G "&IF(K3="where","","where A >= date '"&TEXT(K3,"yyyy-mm-dd")&"'")&"
"&IF(K4="","","and A <= date '"&TEXT(K4,"yyyy-mm-dd")&"'")&"
"&IF(K5="","","and B matches '"&UPPER(K5)&"'")&"
"&IF(K6="","","and C matches '"&UPPER(K6)&"'")&"
",1)
It works fine but, when all the arguments return false, I get the whole range, presumably as the query becomes just select A,B,C,D,E,F,G.
Is there any way I can force it to return nothing, or an error even. I Tried just putting a random OR C matches 'nothing' at the end but it still returned everything.
Chris, you could put an IF statement around the whole QUERY. Something like:
=IF(AND(K3="where",K4="",K5="",K6=""),"",QUERY(....))
Would that work for you?

Exact match in dget function with an array as the criteria

Example Sheet I'm trying to get an exact match with an array in the criteria section of dget. Maybe there is another way to work around this, but I'm trying to give it a dynamic component in the array.
=dget('Micro Data'!$A$1:J,"PCR Score",{"Micro Type","Stage Type","Tank","ID#";"PCR PAL","Bright",F2,H2})
Sometimes all criteria matches multiple data points except the "Tank". However the tanks won't exactly match. Ex. All the data is the same in two data sets, except the tanks are CT1 and CT18. This then comes up with the #NUM! error. I'm trying to find if there is a way to get an exact match in the array data while still allowing it to reference the cell?
I know there is the option of making it "=XXX" making it a txt string, but this would take away the dynamic function. I would also loose the auto updating aspect when more data is added.
Thanks
Ryan, see my solution using a query, in Retain Log-GK, cell F2. I think it is just as dynamic as the dget, but perhaps not. It will need some error wrapping to avoid errors if no result found.
Formula is basically:
=query('Criteria Source'!A2:J5,
"select J where B = '"&D9&"' and C = '"&D10&"' and E = '"&D11&"' and D ='"& D2 & "' ",0)
I made all of the criteria dynamic, though obviously you can do it whatever way suits you best...
Let me know of any questions. I'll check back later...

How can I repeat a query with multiple columns N times with a join who only take ONE column?

I am using this:
=IFERROR(QUERY(Opgivelser!A:E; "select D,A,B where E = TRUE");"Vælg fordybelsesområder")
for this:
And it works as intended but I also want to repeat it i.e twice or based on a cells value i.e D2.
I have tried to to use this:
=ArrayFormula(TRANSPOSE(SPLIT(JOIN(","; IFERROR(REPT(IFERROR(QUERY(Opgivelser!A:E; "select D,A,B where E = TRUE"); "Vælg fordybelsesområder") & ","; D2))); ",")))
But that one prompts an error about ONE row/column.
What will I have to change? Or is there an even more simple or logical syntax for this?
try:
=ARRAYFORMULA(SPLIT(TRANSPOSE(SPLIT(REPT(QUERY(TRANSPOSE("♠"&
QUERY(TRANSPOSE("♦"&IFERROR(QUERY(Opgivelser!A:E;
"select D,A,B where E = TRUE"); "Vælg fordybelsesområder"))
;;9^9));;9^9); F1); "♠")); "♦"))

Google Sheets Query with Logic Statements

I am trying to create a list of data from a data range in Google Sheets. I thought of using the query function, but with that, you can't seem to use regular logical statements.
I know that this snippet of code is wrong and doesn't work, but hopefully it makes it clear what I'm trying to do.
=Query(E2:E103, OR(AND(D2:D103=A$2,G2:G103=A$5),AND(D2:D103=A$3,G2:G103=A$5),D2:D103=A$1))
In this code, A$2, A$5, A$3, and A$1 are all just string variables in the corresponding cells that tell the logic statement what to compare.
If there is another way to write this or a different function that accomplishes what I would like to do, it would be greatly appreciated if you could share it with me.
Basic case
The basic syntax for building a query logic:
"where F = '" & A1 & "'"
assumes A1 is a string, values in column F are strings
adds single quotes, makes the resulting query string: where F = 'sample text'
Logic
Your case looks like this:
where (A) or (B) or C =>
where (A1 and A2) or (B1 and B2) or C =>
where (D = 'text1' and G = 'text2') or (D = 'text3' and G = 'text4') or D = 'text5'

Username using * in the criteria countif

i m searching sum of class of each student using countif formula, but any student have unique username like A*di (in the image) and so the calculation is false. And any other student using username like </John>, and 'Angel. and make calculation false
Formula: =COUNTIF('Data Asli'!$A:$A,$A$2)
Use SUMPRODUCT(--EXACT(..)) to run an exact, case-sensitive comparison that ignores wildcards:
=SUMPRODUCT(--EXACT('Data Asli'!$A:$A,$A2))
How it works:
EXACT(Value1, Value2) will return TRUE or FALSE, depending on whether the 2 values exactly match (same capitals, no wildcards, et cetera)
-- will convert TRUE/FALSE into 1/0
SUMPRODUCT(Array1[,Array2]) will run down the arrays, multiply the numbers together, then add them. It also forces many functions to both treat a Range as an array, and output an array.
So, as an example, the steps run like this:
=SUMPRODUCT(--EXACT(A1:A5, A2))
=SUMPRODUCT(--EXACT({Value1,Value2,Value3,Value4,Value2}, Value2))
a.k.a.
=SUMPRODUCT(--{EXACT(Value1,Value2),EXACT(Value2,Value2),EXACT(Value3,Value2),EXACT(Value4,Value2),EXACT(Value2,Value2)})
=SUMPRODUCT(--{FALSE,TRUE,FALSE,FALSE,TRUE})
=SUMPRODUCT({0,1,0,0,1})
=2

Resources