I am trying to type a logical formula like that :
=AND(OR(A1=0;B1);OR(A2=0;B2);OR(A3=0;B3);...;OR(An=0;Bn))
But I own multiples rows and I am searching for a faster way to achieve this operation.
Any idea ?
You can use ARRAYFORMULA()
ARRAYFORMULA
Enables the display of values returned from an array formula into multiple rows and/or columns and the use of non-array functions with arrays.
Sample Formula:
=AND(ARRAYFORMULA(IF(A2:A8=0,1,0)+(B2:B8)))
what this formula does is performing OR operation using "+" for Column A and Column B. Once the OR operation was performed, ARRAYFORMULA will return an array of results which you can use in your AND operation.
Example:
In the first scenario, when you performed an OR operation within the ARRAYFORMULA (See Cell C2, formula was shown in Cell C1) It will return an array of OR operation results per row. Then if you check the formula used in Cell D2, we just get the AND operation of the array results from ARRAYFORMULA
NOTE:
You cannot use AND() or OR() functions inside the ARRAYFORMULA(), instead we use '*' for AND() and '+' for OR().
Reference: ArrayFormula and "AND" Formula in Google Sheets
Related
I can't seem to find the right equation to find a cell from a row that matches only a few specific characteristics. In this example, I am trying to find the equation for Column D which would be the cell in A that has the same cells for B & C.
Hope this makes sense!
I'll provide two options.
If you're sure your data will only ever have zero or one match, you can place the following formula into D2 of an otherwise empty range D2:D...
=ArrayFormula(IF(A2:A="",,SUBSTITUTE(VLOOKUP(B2:B&C2:C,{B2:B&C2:C,A2:A},2,FALSE)&VLOOKUP(B2:B&C2:C,SORT({B2:B&C2:C,A2:A,ROW(A2:A)},3,0),2,FALSE),A2:A,"")))
However, if you think more than one match may turn up and you want "None" to be returned if there is no match, you can use the following formula in D2 or an otherwise empty range D2:D...
=ArrayFormula(IF(A2:A="",,REGEXREPLACE(REGEXEXTRACT(REGEXREPLACE(SUBSTITUTE(VLOOKUP(B2:B&C2:C,TRIM(SPLIT(FLATTEN(QUERY(QUERY({B2:B&C2:C&"~",A2:A&","}, "Select MAX(Col2) where Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1"),, 9^9)),"~")),2,FALSE),A2:A,""),"^[,\s]+$","None"),"([^,\s].+[^,\s])[,\s]*$"),"[,\s]+",", ")))
The second formula will work even if there will only ever be zero or one match; it's just not necessary to have it be that lengthy. And the second formula is only as lengthy because it was unclear from your posted examples whether the data in Col A, B and C will really only ever be one word or not; so the formula is built to assume there will not always be one-word strings in those columns.
Either formula will provide results for the entire column without dragging.
Here's an option, You can use this formula in column D2:
=iferror(textjoin(", ",true,query($A$2:$C,"Select A where A is not null and A != '"&$A2&"' and B = '"&$B2&"' and C = '"&$C2&"'",0)),"None")
Limitation:
You need to manually drag the formula to its succeeding rows. Arrayformula() cannot be used in looping the query string values.
What it does?
Using query(), filter the data from A2:C that has the same current row last name(Column B) and food(Column C) at the same time having a different first name(Column A)
If there are multiple results, use textjoin() to combine them with ", " as its delimiter.
If there is no matched found, it will return an error, hence use iferror() to set the default value to "None"
Output
I'm trying to embed a countif into an array formula in Google Sheets. I'm using the countif command to count the number of cells on another page with a given text string, stored in column B. Column B just contains a list of titles. The concatenate portion does a general keyword lookup.
Here is the formula that does not work. It just returns a 0 in each cell, which tells me the countif statement is failing.
=arrayformula(IF(B2:B<>"",COUNTIF(Registrations!C:C,(CONCATENATE("*", B2, "*"))),""))
If I pull out the countif statement, it works fine by itself.
=COUNTIF(Registrations!C:C,(CONCATENATE("*", B2, "*")))
I have even tried referencing B2:B in place of the B2 cell reference, but that does not work. What did I do wrong in the array formula statement?
Have you tried using & instead of the CONCATENATE function and referencing to B2:B in place of only B2?
The formula should look like this:
=arrayformula(IF(B2:B<>"",COUNTIF(Registrations!C:C,("*" & B2:B & "*")),""))
It works for me.
This is my 'Registrations' sheet:
And this is the sheet where the formula is written:
I was looking a the formula for cumulative sum using arrayformula:
ARRAYFORMULA(SUMIF(ROW(A1:A10), "<=" & ROW(A1:A10), B1:B10))
I used arrayformulas before, but mostly for simple arithmetic, so I am trying to wrap my head around this.
The reason it is unclear for me is that I don't know what the rules are for ARRAYFORMULA to use the range, or to use the scalar value.
If I tabulate it it becomes something like this:
row 1: SUMIF(ROW(A1:A10), "<=" & ROW(A1), B1:B10))
row 2: SUMIF(ROW(A1:A10), "<=" & ROW(A2), B1:B10))
...
row n: SUMIF(ROW(A1:A10), "<=" & ROW(An), B1:B10))
But that doesn't actually work because ROW doesn't work like that if not used in an ARRAYFORMULA, according to the docs:
ROW([cell_reference])
if cell_reference is a range more than one cell wide and the formula is not used as an array formula, only the numeric value of the first row in cell_reference is returned.
Looking at the syntax for SUMIF it is:
SUMIF(range, criterion, [sumrange]).
Do I understand it correctly that the rules for ARRAYFORMULA are:
If a function parameter inside ARRAYFORMULA is expected to be a scalar (criterion in the examle) and a range is given it will expand in the cells below iterating this range
If a function parameter inside ARRAYFORMULA is expected to be a range (range and sumrange) and a range is given it will pass on the range to the formula
So, the question is:
What is exactly happening row by row with the formula pasted above and how does ROW behave in this? ROW is 'aware' that it is being used in an arrayformula and behaves differently?
It's not about the ROW. Its more about the & and the strings used. Used inside a arrayformula, it creates series(a array) of strings. So, "<="&ROW(A1:A10) becomes "<1","<2" and so on. Criterion argument of SUMIF expects a string and only a single string. Given the array, it creates a array of results for each criterion, the Range argument being the same for each criterion. Also, SUMIF already expects array for the range argument.
If any of the queries in an array formula do not have actual data to query in the range they are hitting they return #VALUE! and mousing over the array formula reveals an error. If I take those queries and wrap them in an IFERROR I get the same results.
If I take what I wrapped in an IFERROR and split it out into its own cell to validate the query it results in displaying the error clause which in this case is a 0.
Here is a link to an example sheet.
Sheet1 has sample data.
Sheet2 is intentionally blank to simulate the issue described above.
Sheet3 has three queries on it in various states. The top two are the array formulas I am attempting to work with. The bottom Query is the IFERROR split out into its own cell to show that the query does in fact work when separated from the rest of the sort(arrayformula(etc)).
Try combining both ranges (from both sheets) inside 1 query instead of using 2 queries, and wrap an IFERROR() around that single query:
=ARRAYFORMULA(IFERROR(QUERY({Sheet1!A1:I500; sheet2!A1:I500}, "Select * where Col7='no'", 0), 0))
See if that works for you ?
I'm having trouble with a countif that I am using to count the number of entries in a range. The problem is that the range is populated with an array formula, and when the data changes the cells the array formula added a =CONTINUE(...) to now display -- (minus minus)
=COUNTIF(C6:C, "<>")
Is there a way that the countif could be written to ignore cells with --?
The -- is a way that Google Sheets displays the #VALUE! error. So you can use the IFERROR function to "mask" any of these errors:
=ArrayFormula(COUNTIF(IFERROR(C6:C);"<>"))
or more simply:
=ArrayFormula(COUNTA(IFERROR(C6:C)))
Updated:
Why don't you filter out all cells that are not text or similar to --?
Then use filtered range for countif.
=COUNTIF((ROWS(C6:C)-COUNTIF(C6:C"<>*")) , "ur criteria")
Is there a way your formula array could cast a string other than --?
Check this article
The search you are doing has regular expression.
Writing this on mobile. So please try out and pardon for weird formatting.