Sum Product Question

J

JimS

Why does

=SUMPRODUCT(--(D25:D3000="reds")*(G25:G3000="x"),(M25:M3000))

work but

=SUMPRODUCT(--(D25:D3000="reds"),(G25:G3000="x"),(M25:M3000))

doesn't?
 
P

Pete_UK

Try it this way:

=SUMPRODUCT(--(D25:D3000="reds"),--(G25:G3000="x"),(M25:M3000))

The double unary minus converts the Trues and Falses to 1s and 0
respectively, but in your second example the second term did not have
this operation.

Hope this helps.

Pete
 
J

JoeU2004

JimS said:
Why does
=SUMPRODUCT(--(D25:D3000="reds")*(G25:G3000="x"),(M25:M3000))
work but
=SUMPRODUCT(--(D25:D3000="reds"),(G25:G3000="x"),(M25:M3000))
doesn't?

First, you can simply the working form, namely:

=SUMPRODUCT((D25:D3000="reds")*(G25:G3000="x"),M25:M3000)

The reason the second form returns an error is that the second argument,
(G25:G3000="x"), returns a boolean (TRUE, FALSE) instead of a number.
SUMPRODUCT requires the latter.

The purpose of "--" is to convert a boolean result into a numeric one. The
"--" is double negation; for example, 5 and -5 are different, but 5 and --5
are the same: -(-5).

But any arithmetic operation involving boolean values will accomplish the
same goal. That is why no "--" is needed in the first form; multiplication
("*") is sufficient.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top