You are on page 1of 12

This workbook demonstrates numerous examples of one of the most powerful, but underused, features of

Excel: array formulas.

An array formula works on whole ranges of the worksheet at once. Suppose that we have two ranges of
numbers:

1 5
2 6
3 7
4 8

Now, suppose that as an input to a formula, we need to know the product of the corresponding values in
each array (e.g., 1*5, 2*6, etc). We can create an array of these products with A1:A4*B1:B4 (assuming the
original values are in those ranges). The resulting array would be {5,12,21,32}. The example to the right
shows how this works.

Suppose that we need to know the results of dividing each number in K4:K13 by L4:L13. We could create
in M4 the formula: =K4/L4 and then copy this down. That would give us the result that we need.
Alternatively, we could create an array. First select M4:M13. Now, type in the formula: =K4:K13/L4:L13
and then hold down Ctrl and Shift while pressing the Enter key. If you look at one of the cells in the array,
you will see that the formula is: {=K4:K13/L4:L13}. Notice that Excel has added the curly brackets
indicating that this is an array formula. If you were to just press the Enter key (neglecting to hold down Ctrl
and Shift) you would get only the value in M4.

So, what's the advantage? Well, in this case nothing really. However, as we'll see, array formulas are much
more efficient than regular formulas in two ways:
1) They save space in the worksheet. Using array formulas we can eliminate columns showing intermediate
results. This also makes the worksheet easier to read because it isn't cluttered up by unnecessary
information.
2) They calculate more quickly than the equivalent series of individual formulas.

Follow along with the examples, and your spreadsheet skills will improve markedly.
Resulting
Number Divisor Array
10 10 1
20 10 2
30 10 3
40 10 4
50 10 5
60 10 6
70 10 7
80 10 8
90 10 9
100 10 10
Weight Score
0.1 95 What this spreadsheet does:
0.2 85 This sheet demonstrates how to calculate a weighted average, variance, and standard d
0.4 75 array formulas. Note that I could have used the SumProduct function to calculate the
0.2 65 but Excel has no function to calculate standard deviation when the weights are unequa
0.1 55
Had I used normal formulas, I would have had to add a column or two to do intermed
Weighted Average 75 The array functions are much more efficient in terms of speed of calculation and in th
Variance 120 spreadsheet space they consume.
Standard Deviation 10.95

How the array functions work:

Weighted Average:
Array functions work on whole ranges at a time, rather than individual cells. The wei
the most simple. The formula is =SUM(A2:A6*B2:B6). First, the formula says "take
A2:A6 and multiply it by the corresponding value in B2:B6. This creates an array (or
Sum function simply calculates the total of all of the elements of the array.

Variance:
This is a bit more complicated, but the logic is similar. The formula is =SUM((B2:B6
AVERAGE(B2:B6))^2*A2:A6). To calculate the variance, we subtract the average of
outcomes from each possible outcome, square the difference, multiply by the probabli
and finally sum the results. Let's break this formula down to its parts in order of calcu

The first part takes each value in B2:B6 and subtracts the average of these values. Th
of deviations from the mean. Next, each value in this array is squared resulting in an
deviations from the mean. Now, we calculate a weighted average of these squared dev
multiplying each squared deviation by its probability of occurance and summing the r

Standard Deviation:
The standard deviation is calculated by finding the square root of the variance. The ea
this would be to use =sqrt(B8), but we don't have to use a cell for the variance calcula
we only care about the standard deviation, so we would use the formula: =SQRT(SUM
AVERAGE(B2:B6))^2*A2:A6)). This is the same formula as before, but we have add
function around the whole thing.
ge, variance, and standard deviation using
ct function to calculate the weighted average,
hen the weights are unequal.

umn or two to do intermediate calculations.


eed of calculation and in the amount of

n individual cells. The weighted average is


First, the formula says "take each value in
6. This creates an array (or vector), and the
nts of the array.

e formula is =SUM((B2:B6-
we subtract the average of all possible
ce, multiply by the probablility of occurance,
to its parts in order of calculation:

verage of these values. The result is an array


y is squared resulting in an array of squared
verage of these squared deviations by
curance and summing the results.

oot of the variance. The easiest way to do


ell for the variance calculation. Normally,
e the formula: =SQRT(SUM((B2:B6-
a as before, but we have added the SQRT()
Product Month Unit Sales
A January 25 What this spreadsheet does:
We have a list of products and their unit sales by month. We wish to determine h
B January 50 of each product were sold over the entire six-month period. Additionally, we wis
C January 17 how many units were sold during each of the six months.
A February 20
B February 42
How the array functions work:
C February 26
To calculate the total sales of Product A, the formula is:
A March 19 =SUM(($A$2:$A$19=A22)*($C$2:$C$19)). This is less complicated if we brea
B March 48 into parts:
C March 21
The first part, ($A$2:$A$19=A22), creates an array of True/False (boolean) value
A April 16
in mind that True = 1 and False = 0, so we have an array of 0's and 1's. Excel loo
B April 35 cell in A2:A19 and determines if the value is the same as that in A22, in this case
C April 19 is, it puts a 1 in the array, if not it puts in a 0. So, we get an array that looks like t
A May 24 {1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0}.
B May 52
Next, we multiply this array by the array of unit sales in C2:C19. Obviously, mu
C May 23 anything by 0 returns a 0, so the new array will be populated by sales for January
A June 21 will look like this: {25,0,0,20,0,0,19,0,0,16,0,0,24,0,0,21,0,0}.
B June 47
C June 22 Finally, the Sum function simply calculates the total of each of the values in this a
Product A it is 125 units. Each of the other two array formulas work in exacly the
way, except that the product name is different.
Product Total Units
A 125 Calculating monthly sales works in exactly the same way, except that the criteria
B 274 name of the month rather than the name of the product.
C 128 Note that we could sort the list in any way (by product, by month, or by units) an
formulas will still work perfectly.
Month Total Units
January 92
February 88
March 88
April 70
May 99
June 90
by month. We wish to determine how many
month period. Additionally, we wish to know
six months.

ormula is:
This is less complicated if we break it down

array of True/False (boolean) values. Keep


e an array of 0's and 1's. Excel looks at each
he same as that in A22, in this case "A". If it
So, we get an array that looks like this:

it sales in C2:C19. Obviously, multiplying


l be populated by sales for January only. It
0,24,0,0,21,0,0}.

e total of each of the values in this array. For


o array formulas work in exacly the same

e same way, except that the criteria is the


product.

product, by month, or by units) and our


Year Sales
What this spreadsheet does:
1990 1205
We have a listing of sales year by year over the past 12 years and wish to
1991 1275 compound average annual rate of sales growth has been over this period.
1992 1346 calculate the standard deviation of sales growth.
1993 1395
Note that we need to deal with growth rates, not dollar growth of sales. F
1994 1500
forecasting purposes, the growth rates are much closer to the ideals of stat
1995 1452 and variance than are the dollar amounts. Also, we really should use the g
1996 1520 rate of growth, not the arithmetic (typical) rate of growth.
1997 1592
1998 1675
1999 1734 How the array functions work:
2000 1793 There's really nothing too complicated (or new) in these functions. In the
2001 1846 we use a built-in function on the array of growth rates. To calculate the ar
use the formula: B3:B13/B2:B12-1. This takes each cell in B3:B13 and d
corresponding value in B2:B12. We then subtract 1 to get the percentage
Using Built-in Functions and Arrays
Arithmetic Average Growth Rate 3.99% The alternative array formulas are a little more complicated, but the idea i
Compound Average Growth Rate 3.95% advantage to using them, I'm merely showing how it could be done. At th
able to figure them out.
Standard Deviation of Growth Rate 2.73%

Alternative Array Formulas


Arithmetic Average Growth Rate 3.99%
Compound Average Growth Rate 3.95%
Standard Deviation of Growth Rate 2.73%
er the past 12 years and wish to know what the
owth has been over this period. It also shows how to
rowth.

es, not dollar growth of sales. For analysis and


much closer to the ideals of stationarity in the mean
Also, we really should use the geometric (compound)
) rate of growth.

r new) in these functions. In the first set of formulas,


growth rates. To calculate the array of growth rates, we
takes each cell in B3:B13 and divides it by the
subtract 1 to get the percentage change.

more complicated, but the idea is the same. There's no


wing how it could be done. At this point, you should be
DATE S&P 500 IBM GM
Dec-96 740.74 37.88 55.75 S&P 500 IBM GM
Jan-97 786.16 39.22 59.00 Total Return 55.19% 227.10% -13.72%
Feb-97 790.82 35.94 57.88 Monthly Return 0.74% 1.99% -0.25%
Mar-97 757.12 34.31 55.38 Standard Deviation 5.16% 10.36% 10.80%
Apr-97 801.34 40.13 57.88 Coef. of Variation 7.02 5.19 (43.96)
May-97 848.28 43.25 57.38 Beta 1.00 1.24 1.14
Jun-97 885.14 45.13 55.75
Jul-97 954.31 52.88 61.88 What this spreadsheet does:
Aug-97 899.47 50.69 62.75 We wish to compare two stocks (IBM and GM) to each other and a b
Sep-97 947.28 53.00 66.94 The comparison consists of total return over the five-year period, com
Oct-97 914.62 49.25 64.19 return, standard deviation of monthly returns, coefficient of variation
Nov-97 955.40 54.75 60.94
This worksheet demonstrates the efficiency of array functions. If we
Dec-97 970.43 52.31 60.75 would have to add three columns to calculate the monthly returns. T
Jan-98 980.28 49.38 57.94 space in the worksheet, but it would require an additional 180 calcula
Feb-98 1049.34 52.22 68.94 clutter the worksheet.
Mar-98 1101.75 51.94 67.75
There are no new techniques here, the calculations all use the same te
Apr-98 1111.75 57.94 67.38 Growth" worksheet.
May-98 1090.82 58.75 71.88
Jun-98 1133.84 57.41 66.81
Jul-98 1120.67 66.25 72.31
Aug-98 957.28 56.31 58.13
Sep-98 1017.01 64.25 54.88
Oct-98 1098.67 74.25 63.19
Nov-98 1163.63 82.56 69.88
Dec-98 1229.23 92.19 71.56
Jan-99 1279.64 91.63 89.75
Feb-99 1238.33 84.88 82.56
Mar-99 1286.37 88.63 87.00
Apr-99 1335.18 104.59 89.06
May-99 1301.84 116.00 69.00
Jun-99 1372.71 129.25 66.00
Jul-99 1328.72 125.69 61.13
Aug-99 1320.41 124.56 66.25
Sep-99 1282.71 121.00 62.94
Oct-99 1362.93 98.25 70.44
Nov-99 1388.91 103.06 73.80
Dec-99 1469.25 107.88 72.69
Jan-00 1394.46 112.25 80.56
Feb-00 1366.42 102.75 76.06
Mar-00 1498.58 118.38 82.81
Apr-00 1452.43 111.50 93.63
May-00 1420.60 107.31 70.63
Jun-00 1454.60 109.56 58.06
Jul-00 1430.83 112.25 56.94
Aug-00 1517.68 132.02 70.00
Sep-00 1436.51 112.63 65.00
Oct-00 1429.40 98.50 62.13
Nov-00 1314.95 93.50 49.50
Dec-00 1320.28 85.00 50.94
Jan-01 1366.01 112.00 53.70
Feb-01 1239.94 99.90 53.32
Mar-01 1160.33 96.18 51.85
Apr-01 1249.46 115.14 54.81
May-01 1255.82 111.80 56.90
Jun-01 1224.38 113.50 64.35
Jul-01 1211.23 105.21 63.60
Aug-01 1133.58 99.95 54.75
Sep-01 1040.94 91.72 42.90
Oct-01 1059.78 108.07 41.32
Nov-01 1139.45 115.59 49.70
Dec-01 1149.56 123.89 48.10

Historical stock prices provided by CSI, Inc. Historical mutual fund and industry prices provided by Media General Financial
GM) to each other and a broad market index (S&P 500).
r the five-year period, compound average monthly
s, coefficient of variation of monthly returns, and betas.

of array functions. If we used non-array functions, we


te the monthly returns. This would not only take more
an additional 180 calculations and would needlessly

lations all use the same technique as shown in the "Sales


Media General Financial Services.

You might also like