Why two minus signs "--" in an excel formula?


Using two minus signs next to each other causes the formula to convert a return value of “TRUE” into 1 and a return value of “FALSE” into 0.

Let’s start with a simple logical condition :3 > 2 .

Apply this in excel = 3>2 returns “TRUE” . Using “—“ two minus signs together with this condition returns 1 = --(3>2)
This method is mostly used in SUMPRODUCT formulas to convert the conditional arrays that evaluates to TRUE/FALSE into 1/0.

Note : SUMPRODUCT formula ignores non numeric cells. Using double minus signs technique we can command excel to convert TRUE/FALSE to 1/0.

Following the values in cell A1:B8

A B
1
X
Y
2
20
2
3
10
5
4
5
8
5
15
11
6
7
14
7
8
17
8
13
20


Use this formula =SUMPRODUCT(--(A2:A8<12),B2:B8)

The first minus sign coerces the array to (0,-1,-1,0,-1,-1,0) and the second minus sign multiplies each values with negative sign [ Basic Maths : (-) * (-) = + ] (0,1,1,0,1,1,0)

So the sumproduct evaluates =SUMPRODUCT((0,1,1,0,1,1,0),(2,5,8,11,14,17,20)) returns a value 44.

You can figure out the same thing using the below formula :
=SUMPRODUCT((A2:A8>10)*B2:B8)

Excel Tutorials : 100 Excel Tutorials
About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 8 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Telecom and Human Resource.

While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*
Related Posts:
4 Responses to "Why two minus signs "--" in an excel formula?"
  1. Superb. Thanks for sharing your knowledge.

    Can you please also add one of the most power full excel tool "Turning Data into Decisions" i.e. PivotTable, PowerPivot and PivotCharts?

    ReplyDelete
  2. So in the first example we are wanting to add the values in column B where the value in column A is less than 12.

    ReplyDelete
  3. Your example looks confusing to me. Could you elaborate what you are this formula exactly is doing please? Formula With minus in first array and without in the second formula?

    ReplyDelete

Next → ← Prev