Question> Sumproduct multiple variables... count only certain results

collegeitdept

Board Regular
Joined
Nov 14, 2008
Messages
185
Hello I need a Sumproduct like formula that will return the count of how many weeks there are for Season 1 (or variable # for season) for a certain show & platform:





[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]M[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]Show1[/TD]
[TD]Show1[/TD]
[TD]Show1[/TD]
[TD]Show1[/TD]
[TD]Show2[/TD]
[TD]Show2[/TD]
[TD]Show2[/TD]
[TD]Show2[/TD]
[TD]Show3[/TD]
[TD]Show3[/TD]
[TD]Show3[/TD]
[TD]Show3[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Date[/TD]
[TD]Platform1[/TD]
[TD]Platform2[/TD]
[TD]Platform3[/TD]
[TD]Season[/TD]
[TD]Platform1[/TD]
[TD]Platform2[/TD]
[TD]Platform3[/TD]
[TD]Season[/TD]
[TD]Platform1[/TD]
[TD]Platform2[/TD]
[TD]Platform3[/TD]
[TD]Season[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]9/15[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]368[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]139[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]6945[/TD]
[TD][/TD]
[TD]4312[/TD]
[TD]168[/TD]
[TD]765[/TD]
[TD]1[/TD]
[TD]864[/TD]
[TD]25357[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]20369[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]9/22[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]7118[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]19645[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]56355[/TD]
[TD][/TD]
[TD]8763[/TD]
[TD]854[/TD]
[TD]8254[/TD]
[TD]1[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]20369[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]978[/TD]
[TD]852[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]9/29[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]17899[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]648[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]45[/TD]
[TD]1[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]20369[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]4569[/TD]
[TD]853[/TD]
[TD]1[/TD]
[TD]78465[/TD]
[TD]8978[/TD]
[TD]453[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]10/6[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]20361[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]20369[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]9465[/TD]
[TD]1[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]648[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]139[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]65478[/TD]
[TD]1[/TD]
[TD]1476[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]139[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]20369[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]10/13[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]17726[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]272[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]4535[/TD]
[TD]1[/TD]
[TD]8654[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]20369[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]1235[/TD]
[TD]1[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]327[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]865[/TD]
[TD]7856[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]10/20[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]19650[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]177[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]4135[/TD]
[TD]1[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]19645[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]4632[/TD]
[TD]642[/TD]
[TD]1[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]19645[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]327[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]2220[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]10/27[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]12026[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]354[/TD]
[TD]5343[/TD]
[TD][/TD]
[TD]536[/TD]
[TD]4535[/TD]
[TD]21656[/TD]
[TD]1[/TD]
[TD]2435[/TD]
[TD]4547[/TD]
[TD]78[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]11/3[/TD]
[TD]45345[/TD]
[TD]455[/TD]
[TD]8936[/TD]
[TD][/TD]
[TD]548[/TD]
[TD]3213[/TD]
[TD]37856[/TD]
[TD]1[/TD]
[TD]853[/TD]
[TD]6951[/TD]
[TD]2356[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]11/10[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]95[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]218[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]2372[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]2220[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]456[/TD]
[TD]35436[/TD]
[TD]1[/TD]
[TD]321[/TD]
[TD]2356[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]544[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]


The formula I have is this (it doesn't work naturally - because it's applying a condition on results?)

=SUMPRODUCT(($B$2:$M$2="Season")*($B$1:$M$1=SHOW)*($A$3:$A$100>=START OF DATE RANGE)*($A$3:$A$100<=END OF DATE RANGE),$B$3:$M$100=1)



Results should be:



Between Dates

Start of Date Range: 9/22/2013
End of Date Range: 11/10/2013

"Show1"
Season: "1"

Count of episodes: 4



"Show2"
Season: "1"

Count of episodes: 8


"Show3"
Season: "2"

Count of episodes: 4
 
I'm not getting your formula to work either.

Any solutions?


Hi dgyang


I got it to work thank you!


I have one last question, going along your excellent formula: =SUMPRODUCT(($B$2:$M$2="Season")*($B$1:$M$1="Show1")*($A$3:$A$92>=$P$9)*($A$3:$A$92<=$P$10),--($B$3:$M$92=1))


How would I then use it as a regular sumproduct?

IE:

Show1
Season 1
Start Date: 9/22/2013
End Date range: 11/10/2013

Count of Episodes: 4

Totals:
Platform1: 75636
Platform2: 21466
Platform3: 18180



and so on....
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Ahh...now I understand. :)

The #VALUE! error I received was because the DATEVALUE function shouldn't be used when referencing the StartOfDateRange cell (which is already a serial date). It is needed for a specific date string as in your example formula: DATEVALUE("22/9/13").

More importantly, I see how SUMPRODUCT can use criteria in both directions (rows and columns). I've only used SUMPRODUCT to match criteria in one direction, and this example is illuminating.

Well done and thanks dgyang! :beerchug:
 
Upvote 0
Ahh...now I understand. :)

The #VALUE! error I received was because the DATEVALUE function shouldn't be used when referencing the StartOfDateRange cell (which is already a serial date). It is needed for a specific date string as in your example formula: DATEVALUE("22/9/13").

More importantly, I see how SUMPRODUCT can use criteria in both directions (rows and columns). I've only used SUMPRODUCT to match criteria in one direction, and this example is illuminating.

Well done and thanks dgyang! :beerchug:



Agreed! Thanks dgyang!


Do you dgyang or JS411 know how to then do a "regular" sumproduct? IE: add all the values for Platform1 for Show1 of Season 1 throughout 9/22/2013 - 11/10/2013


Count of Episodes: 4

Totals:
Platform1: 75636
Platform2: 21466
Platform3: 18180


thanks!
 
Upvote 0
Actually, Dyangs formula works fine aswell, I had the same problem with the datevalue.

If you want to totals for the platform1,2 and 3, you'd have to check wether Row 2 is "Platform1" etc.
and instead of the check wether the matrix = 1, you'd just have to use the matrix I suppose.

So it would be something like this:
=SUMPRODUCT(($B$2:$M$2="PlatForm1")*($B$1:$M$1="Show1")*($A$3:$A$92>=$P$9)*($A$3:$A$92<=$P$10),($B$3:$M$92))

Not tested, but it should work.
 
Upvote 0
Actually, Dyangs formula works fine aswell, I had the same problem with the datevalue.

If you want to totals for the platform1,2 and 3, you'd have to check wether Row 2 is "Platform1" etc.
and instead of the check wether the matrix = 1, you'd just have to use the matrix I suppose.

So it would be something like this:
=SUMPRODUCT(($B$2:$M$2="PlatForm1")*($B$1:$M$1="Show1")*($A$3:$A$92>=$P$9)*($A$3:$A$92<=$P$10),($B$3:$M$92))

Not tested, but it should work.


It doesn't work. It doesn't take into account only Season 1 values.
 
Upvote 0
This appears to work. It uses the named ranges to reference the cells with the parameters to make it a little easier to follow. You can replace that with direct references to the cells.
Excel Workbook
OP
1ShowShow1
2Season1
3
4StartOfDateRange9/22/2013
5EndOfDateRange11/10/2013
6
7Count of Episodes:4
8
9Totals:
10Platform175636
11Platform221466
12Platform318180
Sheet


In P10 enter this formula then copy down.
Code:
=SUMPRODUCT(
    INDEX(($B$1:$M$1=Show)*($B$2:$M$2="Season")*($B$3:$M$100=Season)*
       ($A$3:$A$100>=StartOfDateRange)*($A$3:$A$100<=EndOfDateRange),0,
       SUMPRODUCT(MATCH(1,($B$1:$M$1="Show1")*($B$2:$M$2="Season"),0)))*
    ($B$1:$M$1="Show1")*($B$2:$M$2=O10)*
    ($B$3:$M$100))
 
Upvote 0
This appears to work. It uses the named ranges to reference the cells with the parameters to make it a little easier to follow. You can replace that with direct references to the cells.

OP
Show
Season
StartOfDateRange
EndOfDateRange
Count of Episodes:
Totals:
Platform1
Platform2
Platform3

<colgroup><col style="width:30px; "><col style="width:116px;"><col style="width:83px;"></colgroup><tbody>
[TD="bgcolor: #cacaca, align: center"]1[/TD]

[TD="align: right"]Show1[/TD]

[TD="bgcolor: #cacaca, align: center"]2[/TD]

[TD="align: right"]1[/TD]

[TD="bgcolor: #cacaca, align: center"]3[/TD]

[TD="bgcolor: #cacaca, align: center"]4[/TD]

[TD="align: right"]9/22/2013[/TD]

[TD="bgcolor: #cacaca, align: center"]5[/TD]

[TD="align: right"]11/10/2013[/TD]

[TD="bgcolor: #cacaca, align: center"]6[/TD]

[TD="bgcolor: #cacaca, align: center"]7[/TD]

[TD="align: right"]4[/TD]

[TD="bgcolor: #cacaca, align: center"]8[/TD]

[TD="bgcolor: #cacaca, align: center"]9[/TD]

[TD="bgcolor: #cacaca, align: center"]10[/TD]

[TD="align: right"]75636[/TD]

[TD="bgcolor: #cacaca, align: center"]11[/TD]

[TD="align: right"]21466[/TD]

[TD="bgcolor: #cacaca, align: center"]12[/TD]

[TD="align: right"]18180[/TD]

</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

In P10 enter this formula then copy down.
Code:
=SUMPRODUCT(
    INDEX(($B$1:$M$1=Show)*($B$2:$M$2="Season")*($B$3:$M$100=Season)*
       ($A$3:$A$100>=StartOfDateRange)*($A$3:$A$100<=EndOfDateRange),0,
       SUMPRODUCT(MATCH(1,($B$1:$M$1="Show1")*($B$2:$M$2="Season"),0)))*
    ($B$1:$M$1="Show1")*($B$2:$M$2=O10)*
    ($B$3:$M$100))



Hi JS411,

Thanks for your response!

I can't get it to work for Show3 (Season2).... it returns 0

=SUMPRODUCT(INDEX(($B$1:$M$1=P1)*($B$2:$M$2="Season")*($B$3:$M$100=P2)* ($A$3:$A$100>=P4)*($A$3:$A$100<=P5),0,SUMPRODUCT(MATCH(1,($B$1:$M$1="Show1")*($B$2:$M$2="Season"),0)))* ($B$1:$M$1="Show1")*($B$2:$M$2=O10)* ($B$3:$M$100))
 
Upvote 0
it also doesn't work for Show2



OP
Show
Season
StartOfDateRange
EndOfDateRange
Count of Episodes:
Totals:
Platform1
Platform2
Platform3

<tbody>
[TD="bgcolor: #CACACA, align: center"]1[/TD]

[TD="align: right"]Show2[/TD]

[TD="bgcolor: #CACACA, align: center"]2[/TD]

[TD="align: right"]1[/TD]

[TD="bgcolor: #CACACA, align: center"]3[/TD]

[TD="bgcolor: #CACACA, align: center"]4[/TD]

[TD="align: right"]9/22/2013[/TD]

[TD="bgcolor: #CACACA, align: center"]5[/TD]

[TD="align: right"]11/10/2013[/TD]

[TD="bgcolor: #CACACA, align: center"]6[/TD]

[TD="bgcolor: #CACACA, align: center"]7[/TD]

[TD="align: right"]8[/TD]

[TD="bgcolor: #CACACA, align: center"]8[/TD]

[TD="bgcolor: #CACACA, align: center"]9[/TD]

[TD="bgcolor: #CACACA, align: center"]10[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]11[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]12[/TD]

[TD="align: right"]0[/TD]

</tbody>




OP
Show
Season
StartOfDateRange
EndOfDateRange
Count of Episodes:
Totals:
Platform1
Platform2
Platform3

<tbody>
[TD="bgcolor: #CACACA, align: center"]1[/TD]

[TD="align: right"]Show3[/TD]

[TD="bgcolor: #CACACA, align: center"]2[/TD]

[TD="align: right"]2[/TD]

[TD="bgcolor: #CACACA, align: center"]3[/TD]

[TD="bgcolor: #CACACA, align: center"]4[/TD]

[TD="align: right"]9/22/2013[/TD]

[TD="bgcolor: #CACACA, align: center"]5[/TD]

[TD="align: right"]11/10/2013[/TD]

[TD="bgcolor: #CACACA, align: center"]6[/TD]

[TD="bgcolor: #CACACA, align: center"]7[/TD]

[TD="align: right"]4[/TD]

[TD="bgcolor: #CACACA, align: center"]8[/TD]

[TD="bgcolor: #CACACA, align: center"]9[/TD]

[TD="bgcolor: #CACACA, align: center"]10[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]11[/TD]

[TD="align: right"]0[/TD]

[TD="bgcolor: #CACACA, align: center"]12[/TD]

[TD="align: right"]0
[/TD]

</tbody>
 
Upvote 0
Oops, I forgot to change a few "Show1" references to the Name Show

My previous suggestion using names should read....
Code:
=SUMPRODUCT(
    INDEX(($B$1:$M$1=Show)*($B$2:$M$2="Season")*($B$3:$M$100=Season)*
       ($A$3:$A$100>=StartOfDateRange)*($A$3:$A$100<=EndOfDateRange),0,
       SUMPRODUCT(MATCH(1,($B$1:$M$1=Show)*($B$2:$M$2="Season"),0)))*
    ($B$1:$M$1=Show)*($B$2:$M$2=O10)*
    ($B$3:$M$100))

Revising your current formula should read...
(note that absolute references should be used so you can copy the formula down for the three Platforms).

Code:
=SUMPRODUCT(
      INDEX(($B$1:$M$1=$P$1)*($B$2:$M$2="Season")*($B$3:$M$100=$P$2)* 
      ($A$3:$A$100>=$P$4)*($A$3:$A$100<=$P$5),0,
      SUMPRODUCT(MATCH(1,($B$1:$M$1=$P$1)*($B$2:$M$2="Season"),0)))* 
      ($B$1:$M$1=$P$1)*($B$2:$M$2=O10)*($B$3:$M$100))
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top