Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does SUMPRODUCT() work for Multiple Criteria Aggregations?

Best of Excel

How does SUMPRODUCT() work for Multiple Criteria Aggregations?

by  SkipVought  Posted    (Edited  )
I most often need to SUM or COUNT rows in a table that meet a set of criteria. The formulae that can be used to accomplish this task include:

SUMIFS(), COUNTIFS(), SUMPRODUCT()

I prefer SUMPRODUCT() because it is much more intuitive.

Here's an example of a simple Structured Table:
[pre]
Table: tSample
Date Name Amt

2/1/2017 Al 22
2/13/2017 Al 33
2/25/2017 Al 23
2/5/2017 Bob 32
2/21/2017 Bob 21
3/9/2017 Bob 12
2/6/2017 Fred 42
2/22/2017 Fred 24
3/3/2017 Al 24
3/17/2017 Bob 14
[/pre]

Here's a summary table:
[pre]
Name 29-Jan [color #204A87]12-Feb[/color] [color #CE5C00]26-Feb[/color] 12-Mar 26-Mar

[color #A40000]Al[/color] 22 [highlight]56[/highlight] 24 0
Bob 32 21 12 14
Fred 42 24 0 0
[/pre]

This is the formula [highlight]here[/highlight]:
=SUMPRODUCT([color #204A87](tSample[Date]>=C$1)[/color]*[color #CE5C00](tSample[Date]<D$1)[/color]*[color #A40000](tSample[Name]=$A2)[/color]*(tSample[Amt]))

Here's how this works:
[pre]
Table: tSample 12-Feb 26-Feb SUM=56
Date Name Amt [color #204A87](tSample[Date]>=F$1)[/color] * [color #CE5C00](tSample[Date]<G$1)[/color] * [color #A40000](tSample[Name]=$E2)[/color] * (tSample[Amt])

2/1/2017 Al 22 Al FALSE * TRUE * TRUE * 22 = 0
2/13/2017 Al 33 Al TRUE * TRUE * TRUE * 33 = 33
2/25/2017 Al 23 Al TRUE * TRUE * TRUE * 23 = 23
2/5/2017 Bob 32 FALSE * TRUE * FALSE * 32 = 0
2/21/2017 Bob 21 TRUE * TRUE * FALSE * 21 = 0
3/9/2017 Bob 12 TRUE * FALSE * FALSE * 12 = 0
2/6/2017 Fred 42 FALSE * TRUE * FALSE * 42 = 0
2/22/2017 Fred 24 TRUE * TRUE * FALSE * 24 = 0
3/3/2017 Al 24 Al TRUE * FALSE * TRUE * 24 = 0
3/17/2017 Bob 14 TRUE * FALSE * FALSE * 14 = 0
[/pre]

So any row where there are all TRUE , the PRODUCT calculates. Otherwise ZERO. Then you get the SUM of the PRODUCTS. If you were to eliminate the (tSample[Amt]) in the SUMPRODUCT, you'll get a COUNT of the rows that meet all the criteria.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top