Why do we use -- after sumproduct(--(A1:A7="somecreteria"))

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Why do we use -- after sumproduct(--(A1:A7="somecreteria"))

Post by BittenApple »

Hello team,
Why -- does after sumProduct?
Regards,
Bita

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Why do we use -- after sumproduct(--(A1:A7="somecreteria"))

Post by HansV »

(A1:A7="somecreteria") returns an array of 7 TRUE/FALSE values: TRUE for each cell whose value is "somecreteria" and FALSE for all other cells.
So for example

{TRUE;FALSE;FALSE;TRUE;FALSE;TRUE;TRUE}

Excel ignores TRUE/FALSE in functions such as SUM and SUMPRODUCT. Using - forces Excel to treat TRUE/FALSE as numbers. TRUE is equivalent to 1 and FALSE to 0. -(A1:A7="somecreteria") turns the above array into

{-1;0;0;-1;0;-1;-1}

The second - changes the -1's to 1's: --(A1:A7="somecreteria") evaluates to

{1;0;0;1;0;1;1}

There is a 1 for each cell whose value is "somecreteria".
SUMPRODUCT adds the 1's, so the result is 4: the number of cells with "somecreteria".
Best wishes,
Hans

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Re: Why do we use -- after sumproduct(--(A1:A7="somecreteria"))

Post by BittenApple »

Hans,
Thanks for all explanation, it is clear now.
Regards,
Bita