Sub topic 6
Changing the Order with Parentheses
This chapter assumes you can enter a formula that starts with =, you can use cell references such as B2, and you know Excel's default order of operations: exponents, then multiplication and division, then addition and subtraction. Here you will learn how parentheses override that order, how nested parentheses are evaluated, and how to avoid the mistakes that come from misplaced or missing parentheses.
Why the default order is not always what you want
Excel follows a fixed precedence. It does not read a formula strictly left to right. When two operators of different rank appear together, the higher-ranked one runs first.
=2+3*4This returns 14, because 3*4 is calculated before the addition. If you meant "add 2 and 3, then multiply by 4", the default order gives the wrong answer. You cannot reorder the operators, so you group the part that must run first.
=(2+3)*4This returns 20. Anything inside parentheses is calculated before the operators outside them. The rule has no exceptions. Parentheses rank above every operator in Excel, including negation, percent, and exponent.
The rule: inside first
When Excel meets a pair of parentheses, it reduces the expression inside to a single value. It then uses that value as if you had typed it in place of the group. The remaining operators then run in their normal order.
The formula below combines parentheses with the exponent operator:
=(2+3)*4^2Excel evaluates it in three steps.
Without the parentheses, =2+3*4^2 returns 50. The exponent gives 16, the multiplication gives 48, and the addition gives 50. The same digits and operators produce a different result, and only the grouping changed.
Where parentheses matter most
Some patterns come up constantly. If you recognize them, you will place parentheses correctly the first time.
Averages and other "sum, then divide" formulas
Division outranks addition. If you want to divide a total, the total must be grouped.
Suppose A1 holds 80, A2 holds 90, and A3 holds 100.
=A1+A2+A3/3This returns about 203.33. Only A3 is divided by 3, and the result is added to the other two values.
=(A1+A2+A3)/3This returns 90, which is the average you intended.
Dividing by a product
Multiplication and division share the same rank, and Excel evaluates equal-rank operators from left to right. That makes a denominator with several parts a common source of mistakes.
=12/2*3This returns 18. Excel computes 12/2 first, which is 6, and then multiplies by 3. If you meant "divide 12 by the product of 2 and 3", group the denominator:
=12/(2*3)This returns 2.
Subtracting a group
Subtraction is not associative. The expression 10-4-2 is read as (10-4)-2, which is 4. To subtract the whole group 4-2, you must say so.
=10-(4-2)This returns 8. A common real-world case is subtracting several costs from revenue: =B2-(C2+D2+E2). Without the parentheses, Excel would subtract C2 but add D2 and E2.
Adjusting a price by a rate
To add a rate to a base value, you multiply the base by 1 plus the rate. The 1+rate part must be grouped, because multiplication outranks addition. This is the pattern from the tax example in the topic plan:
=B2*(1+$F$1)If B2 is 50 and F1 is 8%, the result is 54. Leaving out the parentheses gives =B2*1+$F$1, which returns 50.08. Excel accepts that formula without complaint and returns a plausible-looking wrong number, so nothing warns you.
For a discount, the same pattern uses a minus sign:
=B2*(1-C2)If B2 is 50 and C2 is 20%, the result is 40.
A comparison table
Each row below shows the same inputs with and without parentheses.
| Intent | Formula without parentheses | Result | Formula with parentheses | Result |
|---|---|---|---|---|
| Add first, then multiply | `=2+3*4` | 14 | `=(2+3)*4` | 20 |
| Average of 80, 90, 100 | `=80+90+100/3` | 203.33 | `=(80+90+100)/3` | 90 |
| Divide by a product | `=12/2*3` | 18 | `=12/(2*3)` | 2 |
| Subtract a group | `=10-4-2` | 4 | `=10-(4-2)` | 8 |
| Root as a fractional power | `=8^1/3` | 2.67 | `=8^(1/3)` | 2 |
The last row shows that parentheses are required when an exponent is a fraction. 8^1/3 is read as (8^1)/3, because the exponent operator outranks division. 8^(1/3) takes the cube root and returns 2.
Nested parentheses
You can place one pair of parentheses inside another. Excel evaluates the innermost pair first, then works outward.
Take an invoice line. Suppose B2 holds a unit price of 20, C2 holds a quantity of 3, D2 holds a discount of 10%, and F1 holds a tax rate of 8%.
=B2*C2*(1-D2)*(1+$F$1)Here the two groups are side by side, not nested. Excel reduces each group (0.9 and 1.08) and then multiplies the four values left to right: 20 × 3 × 0.9 × 1.08 = 58.32.
Now consider a formula where one group sits inside another. Compound interest uses this pattern. Suppose A2 holds a principal of 1000, B2 holds an annual rate of 6%, and C2 holds a term in years, here 2.
=A2*(1+B2/12)^(C2*12)Excel evaluates it in this order:
B2/12is 0.005, the monthly rate. This division runs inside the first group before the addition.1+0.005is 1.005, which finishes the first group.C2*12is 24, which finishes the second group.1.005^24is about 1.12716. The exponent outranks the multiplication outside the groups.1000*1.12716is about 1127.16.
Notice that the first group contains a division and an addition. Inside any group, the normal order still applies. Parentheses do not turn off precedence. They only create a smaller region where precedence is applied first.
Excel allows up to 64 levels of nesting in a formula. You will rarely come near that limit. Readability gives out long before it does, so if you find yourself nesting more than three levels, consider splitting the calculation across helper cells.
Parentheses and negation
Negation, the minus sign in front of a value, has a high rank. It is applied before the exponent operator. This produces a result that surprises many people.
=-2^2This returns 4, not -4. Excel negates the 2 first, giving -2, and then squares it. Most written mathematics reads -2² as the negative of 2 squared, so the Excel result differs from that convention. Parentheses let you say exactly what you mean:
=-(2^2)This returns -4. For clarity, many people also write =(-2)^2 when they want the squared negative number, even though it is equivalent to =-2^2. The extra parentheses show your intent to the next reader.
Negation matters when you refer to cells too. If A1 holds -3, then =A1^2 returns 9, because the value in the cell is already negative and nothing is being negated in the formula. If you type =-A1^2 with A1 holding 3, Excel negates first and returns 9, not -9. When a formula mixes a leading minus with ^, group it.
Equal-rank operators and the exponent surprise
Equal-rank operators run left to right. This is why 10-4-2 is 4 and 12/2*3 is 18. The exponent operator follows the same left-to-right rule in Excel:
=2^3^2This returns 64, because Excel evaluates it as (2^3)^2. Some other tools and most mathematical writing treat chained exponents as right to left, which would give 2^(3^2), or 512. If you move formulas between tools, or you need the right-to-left meaning, add the parentheses:
=2^(3^2)This returns 512. Writing the grouping explicitly makes the formula mean the same thing everywhere.
Parentheses with percent
The percent operator % ranks above multiplication and division, so it applies to the value directly in front of it. That is why =10%*200 returns 20. When you want a percentage applied to a sum, group the sum:
=100*(1+10%)This returns 110. Without the parentheses, =100*1+10% returns 100.1, because 10% becomes 0.1 and is added at the end.
Matching pairs
Every opening parenthesis needs a closing one. Excel helps you check this while you type or edit.
- When you type a closing parenthesis, Excel briefly bolds the matching opening one.
- While you edit a formula, each pair of parentheses is shown in its own color, so you can see which closer belongs to which opener.
- If the counts do not match when you press Enter, Excel shows a "There's a problem with this formula" message. In some cases it offers a corrected version. Read the proposed fix before you accept it, because Excel adds the missing parenthesis at the end, which may not be where you meant it to go.
For example, =B2*(1+$F$1 is missing its closing parenthesis, and =B2*1+$F$1) has an extra one. Excel rejects both.
Extra parentheses that do not change the order are legal and harmless. =(B2*C2) returns the same value as =B2*C2. Use them when they make the intent obvious, for example =(B2*C2)+(D2*E2), which returns the same result as =B2*C2+D2*E2. A reader does not need to remember the precedence table to understand the first version.
Checking that your grouping is right
Before you copy a formula down a column, test it on a row where you know the answer.
- Pick a row with simple numbers, such as a price of 100 and a rate of 10%.
- Work out the expected result by hand. For
=B2*(1+$F$1)with a 10% rate, that is 110. - Compare the cell's result with your figure. If they differ, the grouping is the first thing to suspect.
Excel also provides tools for looking inside a formula:
- Select a cell and press
F2to enter edit mode, where the colored parentheses and reference highlighting are visible. - On the Formulas tab, choose Evaluate Formula to step through the calculation one operation at a time. Each step shows the part Excel is about to calculate, underlined.
- In edit mode, select part of the formula in the formula bar and press
F9to replace that part with its calculated value. This is useful for checking a single group. PressEscafterward to restore the original formula, because pressing Enter would keep the typed-in value in place of the formula.
A related error to know about is #DIV/0!. A grouped denominator can evaluate to zero even when no single cell in it is zero. For example, =A2/(B2-C2) fails when B2 and C2 hold equal values. The error appears in the cell that holds the formula, not in the cells that caused it, so check the contents of the denominator group.
Common mistakes
| Mistake | Example | What goes wrong | Fix |
|---|---|---|---|
| Missing group around a sum | `=A1+A2+A3/3` | Only `A3` is divided | `=(A1+A2+A3)/3` |
| Missing group around a denominator | `=A1/B1*C1` when you want to divide by both | Division runs first, then multiplication | `=A1/(B1*C1)` |
| Rate not grouped with 1 | `=B2*1+$F$1` | Adds the rate itself instead of scaling the price | `=B2*(1+$F$1)` |
| Fractional exponent not grouped | `=8^1/3` | The exponent applies to 8 only | `=8^(1/3)` |
| Leading minus before an exponent | `=-2^2` | Returns 4 instead of -4 | `=-(2^2)` |
| Unbalanced parentheses | `=B2*(1+$F$1` | Excel rejects the formula | Add the closing `)` |
| Implied multiplication | `=(2+3)(4)` | Excel rejects the formula | `=(2+3)*4` |
Most of these formulas calculate without any error message. The first four return a number that looks reasonable. For that reason, the habit of testing with a known answer is more reliable than waiting for Excel to tell you something is wrong.
Summary of the rules
- Parentheses are evaluated before every operator outside them.
- With nested parentheses, the innermost pair runs first, then Excel works outward.
- Inside any pair, normal precedence and left-to-right order still apply.
- Negation applies before
^, and chained^operators run left to right. - Write
*explicitly. Excel does not infer multiplication. - Add extra parentheses when they make your intent clearer, and test grouped formulas on a case where you know the answer.
Exercise
Cells A1, A2, and A3 hold 6, 9, and 12. What does =A1+A2+A3/3 return, and how do you change it so it returns the average of the three cells?
Show answer
It returns 19, because only A3 is divided by 3 (12/3 = 4) and the result is added to 6 and 9. Group the sum: =(A1+A2+A3)/3, which returns 9.
Exercise
B2 holds a price of 250, and F1 holds a discount rate of 12%. Write a formula that returns the discounted price, and say what =B2*1-$F$1 would return instead.
Show answer
Use =B2*(1-$F$1), which returns 220. The version without parentheses multiplies 250 by 1 first and then subtracts 0.12, so it returns 249.88.
Exercise
Without entering them in Excel, work out the results of =2^3^2, =2^(3^2), and =-3^2. Then write a formula that returns -9 using the number 3.
Show answer
=2^3^2 returns 64 because Excel evaluates exponents left to right, as (2^3)^2. =2^(3^2) returns 512. =-3^2 returns 9 because negation is applied before the exponent. To get -9, write =-(3^2).
Exercise
A2 holds 5000, B2 holds an annual rate of 4%, and C2 holds a term of 3 years. Write a formula for monthly compounding, A2(1+B2/12)^(C212), and name the order in which Excel evaluates its parts.
Show answer
The formula is =A2(1+B2/12)^(C212). Excel first evaluates B2/12 and then 1 plus that result inside the first group, then C2*12 inside the second group. It then raises the first group to the power of the second, and multiplies the result by A2. The value is about 5637.87.