Sub topic 6
Changing the order with parentheses
This chapter assumes you can enter a formula that starts with =, you know Excel's precedence order (negation, then %, then ^, then * and /, then + and -), and you can use cell references such as B2. Here you will use parentheses to override that order and avoid the mistakes people make when they do.
Why you need parentheses
Excel applies its precedence rules before it reads your intent. Multiplication and division run before addition and subtraction, so a formula written the way you would say it aloud often returns the wrong number.
=2+3*4This returns 14, because 3*4 runs first. To add first, put the addition in parentheses:
=(2+3)*4This returns 20. Excel always calculates what is inside parentheses before it uses the result in the rest of the formula.
A realistic example: adding tax
Suppose B2 holds a price of 50 and F1 holds a tax rate of 8%. You want the price plus tax. The correct formula is:
=B2*(1+$F$1)Excel evaluates 1+$F$1 first, which gives 1.08, then multiplies by 50 to get 54. The $F$1 reference is absolute, so it stays fixed when you copy the formula down the column.
Now see what happens without the parentheses:
=B2*1+$F$1Excel multiplies B2*1 first, then adds 0.08, and returns 50.08. Excel reports no error, and the number looks plausible, which makes this kind of mistake easy to miss.
Same-level operators run left to right
Parentheses also matter when operators share the same precedence level. Excel works from left to right in that case.
=10-4-2This returns 4, because Excel calculates 10-4 and then subtracts 2. If you want to subtract the difference of 4 and 2, group it:
=10-(4-2)This returns 8. Division behaves the same way. =100/5*2 returns 40, while =100/(5*2) returns 10. The second form is the one you need when the denominator is a product.
Averages: the classic mistake
The most common beginner error is averaging without grouping. If A1, A2 and A3 hold 6, 9 and 12:
=A1+A2+A3/3This returns 19, because only A3 is divided by 3. The correct formula groups the sum:
=(A1+A2+A3)/3This returns 9. (Later you will use the AVERAGE function for this, but the grouping rule applies to every formula you write.)
Nested parentheses
You can place parentheses inside parentheses. Excel works from the innermost pair outward.
=((2+3)*4-6)/2The steps are:
2+3becomes 5.5*4becomes 20.20-6becomes 14.14/2becomes 7.
The diagram shows the order for a simpler formula that mixes grouped and ungrouped parts.
The parentheses go first. Then multiplication and division run, and the subtraction runs last.
Parentheses and negation
Negation (the minus sign in front of a number) runs before ^, so it can surprise you. Excel treats the minus as part of the number:
=-2^2This returns 4, because Excel squares -2. If you want the negative of 2 squared, group the power:
=-(2^2)This returns -4.
Matching pairs and checking your work
Every opening parenthesis needs a closing one. If the counts differ, Excel shows a message when you press Enter and offers to correct the formula. Sometimes it proposes a fix that is not what you meant, so read the suggestion before you accept it.
Two features help you check nesting:
- While you edit a formula, Excel colors each pair of parentheses differently, and it briefly highlights the partner when your cursor passes over one.
- In the formula bar you can select part of a formula and press F9 to see that part's value. Press Esc afterward to leave the formula unchanged. If you press Enter instead, the selected part becomes a typed-in number.
Summary of the cases
| Formula | Result | Why |
|---|---|---|
| `=2+3*4` | 14 | Multiplication runs first |
| `=(2+3)*4` | 20 | Parentheses run first |
| `=10-4-2` | 4 | Left to right |
| `=10-(4-2)` | 8 | Inner subtraction first |
| `=100/5*2` | 40 | Left to right |
| `=100/(5*2)` | 10 | Denominator grouped |
| `=-2^2` | 4 | Negation before power |
| `=-(2^2)` | -4 | Power inside parentheses first |
Exercise
Cell A1 holds 80 and cell A2 holds 20. You want to subtract A2 from A1 and then halve the result, which should be 30. Which formula is correct, =A1-A2/2 or =(A1-A2)/2? What does the incorrect one return?
Show answer
=(A1-A2)/2 is correct and returns 30. =A1-A2/2 divides A2 by 2 first (giving 10) and then subtracts it from 80, so it returns 70.
Exercise
B2 holds a price of 200 and F1 holds a discount rate of 15%. Write a formula that returns the discounted price and that still works when copied down a column. What value does it return for B2?
Show answer
=B2(1-$F$1). Excel calculates 1-0.15 = 0.85 first, then 2000.85, so it returns 170. The $F$1 reference stays fixed when the formula is copied.