Summary

To count or sum variances, you can use formulas based on the SUMPRODUCT function and ABS function. In the example shown, the formula in F6 sums absolute variances:

=SUMPRODUCT(ABS(variance))

where variance is the named range D5:D15. In other words, the result is the sum of the values in D5:D15 converted to absolute values. See below for details about the other formulas that appear in this example.

Explanation 

In this example, the goal is to sum or count a set of variances in different ways. Variances are listed in D5:D15, which is also the named range variance. The first formula in F5 simply sums all variances with the SUM function.

=SUM(variance) // returns -175

Sum absolute variances

The formula in F6 calculates the sum of absolute variances with the ABS function together with the SUMPRODUCT function:

=SUMPRODUCT(ABS(variance)) // returns 975

In this formula, ABS returns the absolute value of variances to SUMPRODUCT in a single array:

=SUMPRODUCT({25;150;200;225;50;100;25;75;0;75;50})

SUMPRODUCT then returns the sum, 975.

Note: we use the SUMPRODUCT function here instead of the SUM function because SUMPRODUCT can handle many array operations natively without entering the formula in a special way. This means it will work in any version of Excel without special handling. See Why SUMPRODUCT for more information.

Count non-zero variance

The formula in F7 counts the number of absolute variances that are greater than zero (0):

=SUMPRODUCT(--(ABS(variance)>0)) // returns 10

In this formula, ABS returns the absolute values for all variances in an array as explained above:

{25;150;200;225;50;100;25;75;0;75;50}

A logical expression is used to check for variances greater than zero:

{25;150;200;225;50;100;25;75;0;75;50}>0

This returns an array of TRUE and FALSE values:

--{TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;FALSE;TRUE;TRUE}

The double negative (--) converts the TRUE and FALSE values to 1s and 0s and the result is delivered directly to the SUMPRODUCT function:

=SUMPRODUCT({1;1;1;1;1;1;1;1;0;1;1}) // returns 10

which returns a final result of 10.

Count positive and negative variances

The formula in F8 counts the number of positive variances:

=SUMPRODUCT(--(variance>0))
=SUMPRODUCT(--({25;-150;200;-225;-50;100;-25;75;0;-75;-50}>0))
=SUMPRODUCT({1;0;1;0;0;1;0;1;0;0;0})
=4

The formula in F9 counts negative variances:

=SUMPRODUCT(--(variance<0))
=SUMPRODUCT(--({25;-150;200;-225;-50;100;-25;75;0;-75;-50}<0))
=SUMPRODUCT({0;1;0;1;1;0;1;0;0;1;1})
=6

Count absolute variance greater than 100

Finally, the formula in F10 counts absolute variances greater than 100:

=SUMPRODUCT(--(ABS(variance)>100))
=SUMPRODUCT(--({25;150;200;225;50;100;25;75;0;75;50}>100))
=SUMPRODUCT({0;1;1;1;0;0;0;0;0;0;0})
=3

Direct array operation

In the example shown, the variances in column D act as a helper column. However, you can calculate the variances directly in an array operation if needed with the same results. For example, to count positive variances, the formula in F8 is:

=SUMPRODUCT(--(variance>0)) // returns 4

This formula can be rewritten to calculate variance internally like this:

=SUMPRODUCT(--(C5:C15-B5:B15>0)) // returns 4

The named range variance can be replaced with C5:C15-B5:B15 in all formulas above.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.