-- in formula

  • Thread starter Thread starter George Wilson
  • Start date Start date
G

George Wilson

I got a formula from this group recently that looked like
this:
=SUMPRODUCT(--(MONTH(A$3:A$87)=2))

What does the -- do in this function? MS help was not very
helpful on this.
TIA
George
 
George,

The -- is double negation. If you do that to a number, it effectively does
nothing ( a positive number is made negative, then positive, and vice
versa). But if you do it to text, it forces excel to convert it to a number
(if the text is a number, like 1, or 2, etc.). If you do it to boolean
values (TRUE or FALSE), it coerces them to 1 and 0. That's what applies
here.

In this case, MONTH(A$3:A$87)=2 is a boolean statement (it states that the
month = 2, which resolves to TRUE or FALSE). If you select that part of the
formula and press F9 (Calculate), you'll see an array of TRUE and FALSE
values. Be sure to undo that (Ctrl-z), or press Esc, so that the formula
doesn't get changed. But SUMPRODUCT doesn't like boolean values. So
select --(MONTH(A$3:A$87)=2) and press F9, and you'll see an array of 1 and
0 values. They were coerced from TRUE and FALSE by the double negation.
SUMPRODUCT likes that, and adds them up.

Makes you wish you'd taken up archery, doesn't it? :)
 

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

Back
Top