signs -- used in formulas

shodan

Active Member
Joined
Jul 6, 2005
Messages
486
What I often see in a sumproduct formula are these -- signs. eg:

=SUMPRODUCT(--(B1:B25="B");--(C1:C25="S20");A1:A25)

As I read in some post, I guess that they turn true into 1 and false into 0. Is this correct, and what are they exactly? Is this only to use with sumproduct than? I thought that the if statement always gives 0 or 1 by default?

Can some help me understand please.
Tx
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
shodan said:
What I often see in a sumproduct formula are these -- signs. eg:

=SUMPRODUCT(--(B1:B25="B");--(C1:C25="S20");A1:A25)

As I read in some post, I guess that they turn true into 1 and false into 0. Is this correct, and what are they exactly? Is this only to use with sumproduct than? I thought that the if statement always gives 0 or 1 by default?

Can some help me understand please.
Tx
Yes, they coerce.

The condition: B1:B25="B" will return TRUE or FALSE, which are not suitable as is for multiplication.

They must be coerced to their numeric 1/0 equivalents.

Any mathematical operator - +0, *1, -- - will produce this result.

The can be used in any logical statement, not just SUMPRODUCT.

IF statements yield TRUE and FALSE. To prove this, enter "X" in A1. In B1, enter: =IF(A1="A",1)

In C1 enter =A1="X"

In D1 enter: =A1="A"
 
Upvote 0
shodan

B1:B25="B" returns TRUE or FALSE for each of the 25 elements in the array, same for C1:C25="S20" and they are not automatically converted to 1 or 0.

SUMPRODUCT is used to multiply corresponding NUMBERS in arrays and and add the results. Therefore the TRUEs and FALSEs need to be converted to 1s and 0s and this is done by performing some arithmetic operation on them. The -- does that by negating it and then negting the result again. So the -- is not a special symbol, but just two minus signs.

So --TRUE is effectively --1 (which = 1)
and --FALSE is effectively --0 (which = 0)

Hope I've explained that correctly.

Edit: But even if I did, just_jon has done it faster.
 
Upvote 0
thanks all, makes sense and made it clear, but,.. if every operator gives the same result, why using -- in stead of just + ? is this a way of guideline to be followed within formulas?
 
Upvote 0
shodan

The + by itself does not do anything to the TRUE or FALSE but +0 (or *1) would. However, as I understand it -- is more efficient than the other two methods.
 
Upvote 0

Forum statistics

Threads
1,215,555
Messages
6,125,490
Members
449,234
Latest member
slzaleski

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