Use of Two Minus Signs in Excel

Deepanshu Bhalla 4 Comments

In Excel, using double minus signs (--) converts "TRUE" to 1 and "FALSE" to 0.

Example : Let's take a simple logical condition : 3 > 2.

Apply this in Excel = 3 > 2 returns "TRUE". Using "--" (two minus signs together) with this condition i.e. = --(3 > 2) returns 1.

This method is commonly used in the SUMPRODUCT formula to convert conditional arrays which give TRUE/FALSE into 1s and 0s.

Practical Example

Suppose you have the table below and you are asked to calculate the sum of the products of values in the range B2:B8 with the values in the range A2:A8 that are less than 12.

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

Incorrect : =SUMPRODUCT((A2:A8<12),B2:B8) returns 0.
Correct (with double minus sign) : =SUMPRODUCT(--(A2:A8<12),B2:B8) returns 44.

How it works:
  1. (A2:A8<12): This part checks if each value in the range A2:A8 is less than 12 and creates an array of TRUE/FALSE values based on the condition.
  2. The first minus sign converts the array of TRUE/FALSE values to (0,-1,-1,0,-1,-1,0) and the second minus sign multiplies each value by the negative sign. It results to (0,1,1,0,1,1,0). This is basic math: (-) * (-) = +.
  3. SUMPRODUCT function multiplies elements of the two arrays : (0,1,1,0,1,1,0) , (2,5,8,11,14,17,20) and returns a value of 44.

Maths behind the formula:

  1. 0 * 2 = 0
  2. 1 * 5 = 5
  3. 1 * 8 = 8
  4. 0 * 11 = 0
  5. 1 * 14 = 14
  6. 1 * 17 = 17
  7. 0 * 20 = 0

Then the SUMPRODUCT function adds up these products:

0 + 5 + 8 + 0 + 14 + 17 + 0 = 44

Alternatively, you can use the multiply sign (*) in the SUMPRODUCT formula which is used to perform multiplication between arrays.

=SUMPRODUCT((A2:A8<12)*B2:B8)
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

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

4 Responses to "Use of Two Minus Signs in Excel"
  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