Conditional Sums Using a Single Criterion


Often, you need to calculate a conditional sum. With a conditional sum, values in a range that meet one or more conditions are included in the sum. This section presents examples of conditional summing using a single criterion.

The SUMIF function is very useful for single-criterion sum formulas. The SUMIF function takes three arguments:

  • range: The range containing the values that determine whether to include a particular cell in the sum.

  • criteria: An expression that determines whether to include a particular cell in the sum.

  • sum_range: Optional. The range that contains the cells you want to sum. If you omit this argument, the function uses the range specified in the first argument.

The examples that follow demonstrate the use of the SUMIF function. These formulas are based on the worksheet shown in Figure 7-14, set up to track invoices. Column F contains a formula that subtracts the date in column E from the date in column D. A negative number in column F indicates a past-due payment. The worksheet uses named ranges that correspond to the labels in row 1. Various summing formulas begin in row 15.

image from book
Figure 7-14: A negative value in column F indicates a past-due payment.

On the CD 

All the examples in this section also appear on the companion CD-ROM in the file named image from book conditional summing.xlsx.

Summing Only Negative Values

The following formula returns the sum of the negative values in column F. In other words, it returns the total number of past-due days for all invoices. For this worksheet, the formula returns –58.

 =SUMIF(Difference,"<0") 

Because you omit the third argument, the second argument ("<0") applies to the values in the Difference range.

image from book
Let a Wizard Create Your Formula

Excel ships with the Conditional Sum Wizard add-in. After you install this add-in, you can invoke the wizard by choosing Formulas image from book Solutions image from book Conditional Sum. You can specify various conditions for your summing, and the add-in creates the formula for you (always an array formula). The Conditional Sum Wizard add-in, although a handy tool, is not all that versatile. For example, you can combine multiple criteria by using an And condition but not an Or condition. To install the Conditional Sum Wizard add-in

  1. Choose File image from book Excel Options to display the Excel Options dialog box.

  2. Click the Add-ins tab on the left.

  3. Choose Excel Add-Ins from the Manage drop-down list.

  4. Click Go to display the Add-Ins dialog box.

  5. Place a check mark next to Conditional Sum Wizard.

  6. Click OK.

image from book

Note 

You can also use the following array formula to sum the negative values in the Difference range:

     {=SUM(IF(Difference<0,Difference))} 

You do not need to hard-code the arguments for the SUMIF function into your formula. For example, you can create a formula such as the following, which gets the criteria argument from the contents of cell G2:

 =SUMIF(Difference,G2) 

This formula returns a new result if you change the criteria in cell G2.

Summing Values Based on a Different Range

The following formula returns the sum of the past-due invoice amounts (in column C):

 =SUMIF(Difference,"<0",Amount) 

This formula uses the values in the Difference range to determine whether the corresponding values in the Amount range contribute to the sum.

Note 

You can also use the following array formula to return the sum of the values in the Amount range, where the corresponding value in the Difference range is negative:

 {=SUM(IF(Difference<0,Amount))} 

Summing Values Based on a Text Comparison

The following formula returns the total invoice amounts for the Oregon office:

 =SUMIF(Office,"=Oregon",Amount) 

Using the equal sign is optional. The following formula has the same result:

 =SUMIF(Office,"Oregon",Amount) 

To sum the invoice amounts for all offices except Oregon, use this formula:

 =SUMIF(Office,"<>Oregon",Amount) 

Summing Values Based on a Date Comparison

The following formula returns the total invoice amounts that have a due date after May 1, 2007:

 =SUMIF(DateDue,">="&DATE(2007,5,1),Amount) 

Notice that the second argument for the SUMIF function is an expression. The expression uses the DATE function, which returns a date. Also, the comparison operator, enclosed in quotation marks, is concatenated (using the & operator) with the result of the DATE function.

The formula that follows returns the total invoice amounts that have a future due date (including today):

 =SUMIF(DateDue,">="&TODAY(),Amount) 




Excel 2007 Formulas
Excel 2007 Formulas (Mr. Spreadsheets Bookshelf)
ISBN: 0470044020
EAN: 2147483647
Year: 2007
Pages: 212

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net