Dynamic SumProduct to either use key or all values.

Scotster

Board Regular
Joined
May 29, 2017
Messages
59
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Firstly, apolgoies I can't upload any files due to security limitations. I've tried to give the simplest example while covering all the info I hope required.

I'm trying to use Sum product to create charting information from quite a large dataset. I can get it working exactly as I want to, but the formula seems unwieldy. I can't imagine it needs to be this complex so just wondering if anyone can help make it a bit more succinct.

I've created a small example that I hope makes some sense. I've highlighted the formula cells in bold. What I'm looking for is a sum product of the quantities where certain criteria are met.

449 Highlighted cell :

Filter option $A20 is the issue
Code:
=SUMPRODUCT(($D$2:$I$16)*($D$1:$I$1=$A20)*($B$2:$B$16=D$19)*($C$2:$C$16=$B$18))
Above works perfectly if there I want a specific value. It doesn't work in D30 where the filter value is "<>". I'm guessing because ="<>" isn't allowed and should instead be <>""

I've gotten around this with the following:
Code:
=IF($B$28="<>",SUMPRODUCT(($D$2:$I$16)*($D$1:$I$1=$A30)*($B$2:$B$16=D$29)),SUMPRODUCT(($D$2:$I$16)*($D$1:$I$1=$A30)*($B$2:$B$16=D$29)*($C$2:$C$16=$B$28)))

This works but in the actual formula I'm using a potential 3 dynamic filter options for the charts so it looks like the following:
Code:
=IF(AND(C2="<>",C3="<>"),SUMPRODUCT((Summary!$N$9:$CJ$1498)*(Summary!$G$9:$G$1498=C$4)*(Summary!$N$7:$CJ$7=1)*(Summary!$L$9:$L$1498=$B6)),
IF(AND(C2="<>",C3<>"<>"),SUMPRODUCT((Summary!$N$9:$CJ$1498)*(Summary!$G$9:$G$1498=C$4)*(Summary!$N$7:$CJ$7=1)*(Summary!$K$9:$K$1498=C$3)*(Summary!$L$9:$L$1498=$B6)),
IF(AND(C2<>"<>",C3="<>"),SUMPRODUCT((Summary!$N$9:$CJ$1498)*(Summary!$G$9:$G$1498=C$4)*(Summary!$N$7:$CJ$7=1)*(Summary!$H$9:$H$1498=C$2)*(Summary!$L$9:$L$1498=$B6)),
SUMPRODUCT((Summary!$N$9:$CJ$1498)*(Summary!$G$9:$G$1498=C$4)*(Summary!$N$7:$CJ$7=1)*(Summary!$H$9:$H$1498=C$2)*(Summary!$K$9:$K$1498=C$3)*(Summary!$L$9:$L$1498=$B6)))))

This doesn't seem right so I'm just wondering if there is a more succinct way of creating the product total?

1​
1​
1​
2​
2​
2​
Part1BU1P1
28​
19​
147​
179​
90​
93​
Part2BU2P1
94​
10​
10​
113​
153​
105​
Part3BU3P1
53​
114​
92​
137​
175​
87​
Part4BU1P1
172​
74​
163​
66​
131​
57​
Part5BU2P1
159​
145​
67​
172​
43​
151​
Part6BU3P1
47​
170​
76​
195​
125​
37​
Part7BU1P1
195​
107​
154​
69​
156​
127​
Part8BU2P1
108​
90​
48​
179​
12​
88​
Part9BU3P2
180​
148​
68​
64​
23​
122​
Part10BU1P2
80​
97​
4​
193​
50​
127​
Part11BU2P2
34​
7​
4​
68​
199​
89​
Part12BU3P2
85​
171​
114​
94​
118​
33​
Part13BU1P2
16​
54​
198​
3​
74​
18​
Part14BU2P2
198​
155​
85​
20​
22​
60​
Part15BU3P2
22​
171​
19​
182​
90​
182​
FilterP2
BU1BU2BU3
1​
449
483​
978​
2​
465​
458​
908​
FilterP1
BU1BU2BU3
1​
1059
731​
552​
2​
968​
1016​
756​
Filter<>
BU1BU2BU3
1​
0
0​
0​
2​
0​
0​
0​
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
This is one possibility that might help you - Providing your data is as you show it (with columns D:F having your "1" data, G:I having your "2" data)

This formula takes advantage of knowing where the "1" Cols are, and "2" cols are etc..

If you can't layout the data, then it won't work for you, sorry. You can amend it for other datas as you have, but essentially I used it to Filter P1 data to get same results as you in second block.

Book1
BCDEF
18P1BU1BU2BU3
1911059731552
2029681016756
Sheet1
Cell Formulas
RangeFormula
D19D19=BYCOL(TOCOL(FILTER($D1:$F16,($C1:$C16="P1")*($B1:$B16="BU1"),"empty")),LAMBDA(col,SUM(col)))
E19E19=BYCOL(TOCOL(FILTER($D1:$F16,($C1:$C16="P1")*($B1:$B16="BU2"),"empty")),LAMBDA(col,SUM(col)))
F19F19=BYCOL(TOCOL(FILTER($D1:$F16,($C1:$C16="P1")*($B1:$B16="BU3"),"empty")),LAMBDA(col,SUM(col)))
D20D20=BYCOL(TOCOL(FILTER($G1:$I16,($C1:$C16="P1")*($B1:$B16="BU1"),"empty")),LAMBDA(col,SUM(col)))
E20E20=BYCOL(TOCOL(FILTER($G1:$I16,($C1:$C16="P1")*($B1:$B16="BU2"),"empty")),LAMBDA(col,SUM(col)))
F20F20=BYCOL(TOCOL(FILTER($G1:$I16,($C1:$C16="P1")*($B1:$B16="BU3"),"empty")),LAMBDA(col,SUM(col)))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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