1
votes

I have a table like the following:

X 1
X 3
X 2
Y 2
Y 5
Z 3
Z 4

I know I could use SUMIF to calculate the sum of the second column for each value in the first column, e.g., =SUMIF(A1:A7,"X",B1:B7) would give me the sum of values for X: 1+3+2=6. However, I want the product of values in the second column for each value in the first column. I.e., the output would be:

A 6
B 10
C 12

When I try to search for SUMIF but for product, I only see suggestions to use SUMPRODUCT, but that multiplies arrays together and then adds their values, whereas I don't want to sum anything, just multiply all the values within a column.

My only idea is to create a new column with the log of the values, then do EXP(SUMIF(...)) to get the product. However, this will not work if any values are 0 or negative. Is there any way to directly compute the product I want?

2

2 Answers

2
votes

If one has the Dynamic Array formula FiLTER:

=PRODUCT(FILTER(B1:B7,A1:A7="X",0))

enter image description here

You can also use a Pivot Table:

enter image description here

2
votes

There are probably cleverer* ways, but you could use this array formula:

=PRODUCT(IF($A$1:$A$7=D1,$B$1:$B$7))

enter image description here

*Edit - as I said, see Scott's answer. I always forget the new formulas.