I have a spreadsheet where I have used SUMPRODUCT formulas to create a number of dynamic tables. I received a request recently to update the tables to add a couple of additional filters that can be selected by the user. The filters need to allow for selecting a single value or all of the values. My solution to that problem was to include an if statement combined with an OR condition in the SUMPRODUCT formula via the use of a +. So for example my formula would look like this:
=SUMPRODUCT(($H$4:$H$13=IF($C$2="Both","A",$C$2))+($H$4:$H$13=IF($C$2="Both","B",$C$2)))
After implementing that I found out very quickly that this was not enough and that I needed to also subtract out from the above any AND conditions to arrive at a true result. This is the thread that helped me figure out how to this: Thread Link.

So the final formula looks like this:
=SUMPRODUCT(($H$4:$H$13=IF($C$2="Both","A",$C$2))+($H$4:$H$13=IF($C$2="Both","B",$C$2)))-SUMPRODUCT(($H$4:$H$13=IF($C$2="Both","A",$C$2))*($H$4:$H$13=IF($C$2="Both","B",$C$2)))
This worked wonderfully. However, when I attempted to add a second filter criteria the formula would no longer work as the AND subtraction would not subtract the proper amounts any longer.

I’ve attached a file which shows an example of what I’m trying to achieve including the data table, the expected results, and my versions of the formulas.

Sumproduct Example.xls

Bear in mind that my actual formulas are much more complex and include a half dozen other criteria, but I decided to keep these as simple as possible and focus only on the part that I’m unable to figure out.

I hope someone can help!