Conditional Sums Using Multiple Criteria

The examples in the preceding section all used a single comparison criterion. The examples in this section involve summing cells based on multiple criteria.

Figure 17-14 shows the sample worksheet again, for your reference. The worksheet also shows the result of several formulas that demonstrate summing by using multiple criteria.

Figure 17-14. This worksheet demonstrates summing based on multiple criteria.


Using And criteria

Suppose that you want to get a sum of the invoice amounts that are past due and associated with the Oregon office. In other words, the value in the Amount range will be summed only if both of the following criteria are met:

  • The corresponding value in the Difference range is negative.

  • The corresponding text in the Office range is “Oregon.”

If you’re using Excel 2007, the following formula does the job:

=SUMIFS(Amount,Difference,"<0",Office,"Oregon")

The array formula that follows returns the same result and will work in all versions of Excel.

{=SUM((Difference<0)*(Office="Oregon")*Amount)}

Using Or criteria

Suppose that you want to get a sum of past-due invoice amounts or ones associated with the Oregon office. In other words, the value in the Amount range will be summed if either of the following criteria is met:

  • The corresponding value in the Difference range is negative.

  • The corresponding text in the Office range is “Oregon”.

This example requires an array formula:

{=SUM(IF((Office="Oregon")+(Difference<0),1,0)*Amount)}

A plus sign (+) joins the conditions; you can include more than two conditions.

Using And and Or criteria

As you may expect, things get a bit tricky when your criteria consists of both And and Or operations. For example, you may want to sum the values in the Amount range when both of the following conditions are met:

  • The corresponding value in the Difference range is negative.

  • The corresponding text in the Office range is “Oregon” or “California”.

Notice that the second condition actually consists of two conditions joined with Or. The following array formula does the trick:

{=SUM((Difference<0)*IF((Office="Oregon")+
(Office="California"),1)*Amount)}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset