You are on page 1of 17

Excel Array Formula Examples

https://www.vertex42.com/blog/excel-formulas/array-formula-examples.html

This workbook contains examples from the article "Excel Array Formula Examples." Regarding copyright and s
of this file like a book. You may use the ideas and techniques and formulas explained here, but you may not re
worksheet or copy substantial portions from it, just as you would not do so with a book. Thank you. - Jon Wittw

EXAMPLES

Basic Array Formula Example


The following table is used in the article to explain how an array formula works. This example uses 3 separate
formulas. One is a multi-cell array formula, and the other two are single-cell array formulas.

Task Days % Complete Completed


Task 1 10 50% 5 Total % Complete:
Task 2 5 20% 1
Task 3 8 7% 0.56
Task 4 3 50% 1.5 Total % Complete:
Task 5 12 9% 1.08
Totals: 38 24.05% 9.14

Multi-Cell Array Formula: Days Completed (F18:F22)

Formula: {Ctrl+Shift+Enter}: =days*percent_complete

Single-Cell Array Formula: Total days complete (F23)

Formula: {Ctrl+Shift+Enter} =SUM(days*percent_complete)

Single-Cell Array Formula: Total percent complete (E23)

Formula: {Ctrl+Shift+Enter} =SUM(days*percent_complete) / SUM(days)


Nested IF Array Formulas
The following contact and sales log is used to show a few examples of nested IF array formulas.

Contact and Sales Log


Date Contact Sale
1/1/2017 Jim $ 1,000.00
2/25/2017 Bob $ 300.00
7/12/2017 Jim $ 500.00
8/5/2017 Bob $ -
9/10/2017 Jim $ 200.00

MAX-IF Find the last Date that Bob was Contacted Person
=MAX(IF(contact_range="Bob",date_range)) Jim
Bob

MAX-IF Find the Largest Sale for Each Contact Person


=MAX(IF(contact_range="Bob",sale_range)) Jim
Bob

SEE ALSO contextures.com - MAX IF

LARGE-IF Find Jim's second largest Sale Person


=LARGE(IF(contact_range="Jim",sale_range),n) Jim

SMALL-IF Find Bob's second smallest Sale Person


=SMALL(IF(contact_range="Jim",sale_range),n) Bob

NOTE The FALSE values returned by the IF formula are not treated as 0 values by the LARGE
and SMALL functions. If SMALL treated FALSE values as 0 values, the formula would not
work.

SUM-IF Find the total Sales for Jim and Bob Person
=SUM(IF(contact_range="Bob",sales_range)) Jim
Bob

Multiple Criteria SUM-IF Person


=SUM(IF( ( 1*(date_range>=date_value) + Jim
1*(contact_range="Jim") )>0,sale_range))

COUNTIF Alternative: SUM-Boolean Array Formulas


Although there is already a COUNTIF function, the criteria available in the COUNTIF family of functions is limit
alternative method is to do a SUM of boolean results that have been converted to 0s and 1s (FALSE=0, TRUE
results can be converted to 0s and 1s by adding +0, multiplying by *1 and by using double negation.

Count the number of Error values within a range Result


Formula: =SUM( 1*ISERROR(range) ) 2
=SUM( 0+ISERROR(range) ) 2
=SUM( --ISERROR(range) ) 2

Values
67
23
#N/A
#NAME?
blank
=""

Count the number of Blank values within a range Result


Formula: =SUM( 1*ISBLANK(range) ) 1
Note: A formula that returns an empty string "" is NOT blank.

Count the number of values that are NOT blank Result


Formula: =SUM( 1*NOT(ISBLANK(range) ) ) 5

Multi-Criteria Boolean Array Formulas


It's easy to misunderstand how the AND and OR functions behave when using an array formula. It's important
that AND and OR return only a single value, even when used in array formulas. Instead of AND and OR, for m
logical array formulas you need to do the boolean logic by adding boolean values for "or" conditions and by mu
boolean values for "and" conditions.
It's easy to misunderstand how the AND and OR functions behave when using an array formula. It's important
that AND and OR return only a single value, even when used in array formulas. Instead of AND and OR, for m
logical array formulas you need to do the boolean logic by adding boolean values for "or" conditions and by mu
boolean values for "and" conditions.

Contact and Sales Log


Date Contact Sale
1/1/2017 Jim $ 1,000.00
2/25/2017 Bob $ 300.00
7/12/2017 Jim $ 500.00
8/5/2017 Bob $ -
9/10/2017 Jim $ 200.00

Total Sales between 2/1/2017 and 9/1/2017 Start


Formula: =SUM( IF( (date_range>=start) * 2/1/2017
(date_range<=end), sum_range) )

Total Sales where Name = Bob or Date >= 7/1/2017 Start


Formula: =SUM( IF( ((name="Bob")+ 7/1/2017
(date_range>date))>=0, sum_range) )

Sequential Number Arrays


Sequential number arrays like {1,2,3,4,…} are common building blocks used within other array formulas. The f
examples show how to create a variety of different number and date arrays. If you enter these formulas as the
result will be a vertical multi-cell array.

Sequence of Whole Numbers from n to m

Formula: =ROW(1:5)

Formula: =ROW(INDIRECT(n&":"&m)) n
5
m
7

NOTE The results are showing only the first 3 values of the array. Try making n = m in this
example to see what happens. Also note that when the multi-cell array result is larger than
the array the formula returns, the array is filled with NA() errors.

Create an n x1 Vector of Whole Numbers Starting From s

Formula: =s+ROW(INDIRECT(s&":"&s+n-1)) size (n)


3
start (s)
7

NOTE In this example, we can't create a multi-cell array formula that changes in size. So, it's only
the first 3 values that are shown. However, you can use a variable length array like this
within other array formulas.

Sequence of Dates Between Start and End (inclusive)

Formula: =ROW(INDIRECT(start&":"&end)) start


1/1/2018
Formula: =ROW(INDIRECT(INT(start)&":"&INT(end))) end
1/5/2018

Matrix Formulas
Excel provides some key functions for working with matrices. These include MUNIT for creating the identity ma
for matrix multiplication, TRANSPOSE for transposing a matrix or vector, MDETERM for calculating the determ
MINVERSE for calculating the inverse of the matrix. Formulas for some key matrices and matrix manipulation
demonstrated below.

MUNIT(n) - Create an Identity matrix of size n x n

I= =MUNIT(n)

I= 1 0
0 1

Ones Vector and Matrix: Create an array of 1s or the constant c

j= =c+0*ROW(INDIRECT("1:"&n))

J= =c+IF(ISERROR(OFFSET(INDIRECT("A1"),0,0,n,m)),0,0)

j= 1 J= 1 1 1
1 1 1 1
1 1 1 1

INDIRECT and OFFSET or volatile functions. If you have access to the MUNIT function, then a simpler way to
ones matrix is to multiply the Identity matrix by 0 and add 1. The vector can be obtained using INDEX to return
column.

j= =INDEX(c+0*MUNIT(n),0,1)

J= =c+0*MUNIT(n)

j= 1 J= 1 1 1
1 1 1 1
1 1 1 1

Repeating Columns k times

Formula: =MMULT(b,TRANSPOSE(INDEX(1+0*MUNIT(k),0,1)))

x= 1 X= 1 1 1 1
10 10 10 10 10
100 100 100 100 100

Repeating Rows n times

Formula: =MMULT( INDEX(1+0*MUNIT(n),0,1), row)

x= 1 10 100 1000
X= 1 10 100 1000
1 10 100 1000
1 10 100 1000

Row or Column sums using the ONES vector

Column Sum: =MMULT(TRANSPOSE(INDEX(1+0*MUNIT(ROWS(range)),0,1)),range)

Row Sum: =MMULT(range,INDEX(1+0*MUNIT(COLUMNS(range)),0,1))

Column 1 Column 2 Column 3 Row-Sum


Row 1 1 10 100 111
Row 2 2 20 200 222
Row 3 4 40 400 444
Row 4 8 80 800 888

Column-Sum 15 150 1500

MMULT(A,B) - Multiply two matrices

C= =MMULT(A,B)

A= 1 2 B= 2 C= 8
3 4 3 18

TRANSPOSE(A) - Transpose a matrix or array

A 1 2 AT 1 3
3 4 2 4

B This BT This That


That

Diagonal(A) - a matrix where all off-diagonal elements are zero


Formula: Diagonal(A) =range*MUNIT(ROWS(range))

A 1 56 76 Diagonal 1 0
24 2 98 0 2
34 46 3 0 0

Create a Diagonal matrix from a vector

Formula: =b * MUNIT(ROWS(b))

b= 1 Diagonal 1 0 0
2 0 2 0
3 0 0 3

diag(A) - the vector of diagonal elements for a square matrix

Formula: diag(A) =

A= 1 56 76 diag(A)= 1
24 2 98 2
34 46 3 3

trace(A) - the sum of the diagonal elements

Formula: trace(A) =SUM( diag(A) ) = SUM( range*MUNIT(ROWS(range)) )

A 1 56 76 trace(A)= 6
24 2 98
34 46 3

MINVERSE(A) - calculates the inverse of the matrix

Formula: A-1 =MINVERSE(A)

A 1 56 76 A-1 = -0.01753156 0.0129598


24 2 98 0.012695 -0.01005086
34 46 3 0.00403436 0.00723537
MDETERM(A) - calculates the determinant of a matrix

Formula: |A| =MDETERM(A)

A 1 56 76 |A| = 256794
24 2 98
34 46 3

REFERENCES

ARTICLE support.office.com: Guidelines and Examples of Array Formulas


© 2018 Vertex42 LLC

Regarding copyright and sharing, think


d here, but you may not reproduce this
ok. Thank you. - Jon Wittwer

example uses 3 separate array


mulas.

Array Formula
24.05%

SUMPRODUCT

24.05%
ay formulas.

Last Contacted

9/10/2017
8/5/2017

Largest Sale
$ 1,000.00
$ 300.00

n Result
2 $ 500.00

n Result
2 $ 300.00

alues by the LARGE


the formula would not

Total Sales
$ 1,700.00
$ 300.00

>= Date Result


6/1/2017 $ 1,700.00

family of functions is limited. An


and 1s (FALSE=0, TRUE=1). Boolean
ouble negation.

ray formula. It's important to remember


ead of AND and OR, for multiple-criteria
"or" conditions and by multiplying
End Total Sales
9/1/2017 $ 800.00

Name Total Sales


Bob $ 1,000.00

ther array formulas. The following


nter these formulas as they are, the

1st 3 Values
1
2
3

1st 3 Values
5
6
7

ing n = m in this
ray result is larger than

1st 3 Values
7
8
9

ges in size. So, it's only


ength array like this

1st 3 Values
43101
43102
43103

for creating the identity matrix, MMULT


M for calculating the determinant, and
s and matrix manipulation are
ion, then a simpler way to create the
ned using INDEX to return the first
0
0
3

0.0207793
0.00672134
-0.00522598

You might also like