Excel Case Take the free check

SUMPRODUCT in an Excel test: weighted averages and conditions

By Excel Case · Updated

SUMPRODUCT multiplies ranges row by row and adds the results. Finance tests use it for weighted averages, and for conditions SUMIFS can't handle.

In short: =SUMPRODUCT(C2:C4,D2:D4) gives revenue from units and price, here 9,200. Divide by total units for the weighted average price, 36.80. A plain AVERAGE of the prices gives 41.67, which is wrong. For conditions, turn TRUE/FALSE into 1/0 with --, or the result is 0.

The test question

Brief: "What is the average selling price?"

A: ProductB: ChannelC: UnitsD: Price
2NotebookOnline12025
3BagRetail8040
4BottleOnline5060

The answer: weight by units

=SUMPRODUCT(C2:C4,D2:D4)/SUM(C2:C4)

Revenue is 120×25 + 80×40 + 50×60 = 9,200. Units are 250. The average selling price is 36.80.

=AVERAGE(D2:D4) gives 41.67. It treats 50 bottles the same as 120 notebooks. This is the same mistake as averaging margin percentages, which the financial analyst test plants on purpose.

Conditions: the -- trap

"How many product lines sell online?" =SUMPRODUCT(B2:B4="Online") returns 0. The comparison gives TRUE/FALSE, and SUMPRODUCT ignores those.

Add two minus signs to turn them into 1 and 0: =SUMPRODUCT(--(B2:B4="Online")) returns 2.

Online revenue, with the condition multiplied in:

=SUMPRODUCT((B2:B4="Online")*C2:C4*D2:D4) returns 6,000. Multiplying turns TRUE/FALSE into numbers too, so no -- is needed here.

Online average price: 6,000 / 170 units = 35.29.

OR conditions

For "Online or Retail", add the conditions instead of multiplying them: ((B2:B4="Online")+(B2:B4="Retail")). Each row can only be one channel, so the sum is 1 or 0.

All ranges must be the same size, or SUMPRODUCT returns #VALUE!. Avoid whole columns like C:C here, because they're slow.

Questions people ask

What does -- mean in SUMPRODUCT?

It's two minus signs. The first turns TRUE/FALSE into -1/0, and the second flips that to 1/0, so SUMPRODUCT can add them.

SUMPRODUCT or SUMIFS?

Use SUMIFS for plain sums with AND conditions, because it's faster and easier to read. Use SUMPRODUCT for weighted averages, OR conditions, or conditions on a calculation.

How do I calculate a weighted average in Excel?

Divide SUMPRODUCT of the values and weights by the sum of the weights: =SUMPRODUCT(values,weights)/SUM(weights).

Now try one that marks itself

The free check gives you an email, a messy export and 10 minutes. It re-runs your formulas on data you haven't seen and shows what broke.

Start the free check

Keep practising