Introduction To Array Formulas
Introduction To Array Formulas
Introduction To Array Formulas
Array Formulas are formulas that work with arrays, instead of individual numbers, as
arguments to the functions that make up the formula.
=IF(A1=B1,1,0)
This will return either 1, if A1=B1, or 0 if they are not equal. But suppose you want to get
a count of
the number of cells in a range, A1:A10, which are equal to the corresponding cells in
B1:B10. By using an array formula, you can do this with a single formula by passing
arrays to the =IF function, and summing up the results:
=SUM(IF(A1:A10=B1:B10,1,0))
By entering this as an array formula, you are instructing the =IF function to "loop" through
the range A1:A10, compare each element to the corresponding element in B1:B10, and
return an array of 1's and 0's, each element of which indicates the result of each
comparison. The =SUM function adds up this array, and returns a single number indicating
the number of cells in A1:A10 which are equal to their counterparts in B1:B10.
When you use more than one range in an array formula, all of the ranges must contain the
same number of elements. Otherwise, an error is returned.
Array formulas are ideal for counting cells in a
range with multiple criteria. For example, suppose
in A2:A10 we have a product-name, in B2:B10
we have a salesman-name, and in C2:C10 we
have number of units sold:
=SUM((A2:A10="Phone")*(B2:B10="Smith")
*C2:C10)
The ranges are looped though "simultaneously." Element Ai is evaluated in the same
iteration as elements Bi and Ci.
Addition simulates the OR operation. If either one or both conditions are true, addition will
return a non-zero result. Using the example above, we can count the number of sales, in
which either a Fax was sold, or Jones was the salesman (or both).
=SUM(IF((A2:A10="Fax")+(B2:B10="Jones"),1,0))
=SUM(IF(MOD((A2:A10="Fax")+(B2:B10="Jones"),2),1,0))
The MOD operator in the above formula returns 0 when either both conditions (Fax,
Jones) are True or when both are False. It returns 1 only when either exactly one of the
conditions is True.
NAND is an Negative And operation, which returns true when neither or one of the
elements is True. It returns False when BOTH elements are True.
=SUM(IF((A2:A10="Fax")+(B2:B10="Jones")<>2,1,0))
This counts all sales, except those in which Jones sold a Fax.
You can combine these formulas to create rather complex logical tests. Just be careful to
make sure that you parentheses are in the right places.
Suppose we have a matrix in A1:C3. We can use the =MINVERSE function to return the
inverse of this matrix. Since the inverse of a matrix is itself a matrix, we've got to enter the
=MINVERSE function as an array formula.