18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Part II<br />

Working with Formulas and Functions<br />

Summing the “top n” values<br />

In some situations, you may need to sum the n largest values in a range — for example, the top ten values. If<br />

your data resides in a table, you can use autofiltering to hide all but the top n rows and then display the<br />

sum of the visible data in the table’s total row.<br />

Another approach is to sort the range in descending order and then use the SUM function with an argument<br />

consisting of the first n values in the sorted range.<br />

A better solution — which doesn’t require a table or sorting — uses an array formula like this one:<br />

{=SUM(LARGE(Data,{1,2,3,4,5,6,7,8,9,10}))}<br />

This formula sums the ten largest values in a range named Data. To sum the ten smallest values, use the<br />

SMALL function instead of the LARGE function:<br />

{=SUM(SMALL(Data,{1,2,3,4,5,6,7,8,9,10}))}<br />

These formulas use an array constant comprised of the arguments for the LARGE or SMALL function. If the<br />

value of n for your top-n calculation is large, you may prefer to use the following variation. This formula<br />

returns the sum of the top 30 values in the Data range. You can, of course, substitute a different value for 30.<br />

{=SUM(LARGE(Data,ROW(INDIRECT(“1:30”))))}<br />

CROSS-REF<br />

See Chapter 17 for more information about using array constants.<br />

Conditional Sums Using a Single Criterion<br />

Often, you need to calculate a conditional sum. With a conditional sum, values in a range that meet one or<br />

more conditions are included in the sum. This section presents examples of conditional summing by using<br />

a single criterion.<br />

The SUMIF function is very useful for single-criterion sum formulas. The SUMIF function takes three<br />

arguments:<br />

n<br />

n<br />

n<br />

range: The range containing the values that determine whether to include a particular cell in the<br />

sum.<br />

criteria: An expression that determines whether to include a particular cell in the sum.<br />

sum_range: Optional. The range that contains the cells you want to sum. If you omit this argument,<br />

the function uses the range specified in the first argument.<br />

The examples that follow demonstrate the use of the SUMIF function. These formulas are based on the<br />

worksheet shown in Figure 14.13, set up to track invoices. Column F contains a formula that subtracts the<br />

date in column E from the date in column D. A negative number in column F indicates a past-due payment.<br />

The worksheet uses named ranges that correspond to the labels in row 1.<br />

ON the CD-ROM<br />

All the examples in this section also appear on the companion CD-ROM. The file is named<br />

conditional sum.xlsx.<br />

268

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!