Sub topic 5
The Order Excel Calculates In
A formula with several operators can return a different number depending on which operation Excel does first. This chapter covers the rules Excel uses to decide that order, the places where those rules differ from what you might expect, and how to predict a result before you press Enter.
This chapter assumes you can already:
- Select a cell and type a formula that starts with
=. - Use
+,-,*, and/with numbers and cell references. - Recall the basic idea of order of operations from school arithmetic.
Why order matters
Consider this formula:
=2+3*4Reading left to right, you might add 2 and 3 to get 5, then multiply by 4 to get 20. Excel returns 14. It multiplies 3 by 4 first, then adds 2.
Excel does not read formulas strictly from left to right. It follows a fixed ranking of operators called operator precedence. An operator with higher precedence is calculated before one with lower precedence. When two operators have the same precedence, Excel works from left to right.
Two ideas cover almost every case:
- Precedence decides which operator goes first.
- Left-to-right order breaks ties between operators of equal rank.
The precedence table
Excel ranks its operators as shown below. Rank 1 is calculated first.
| Rank | Operator | Name | Example | Result |
|---|---|---|---|---|
| 1 | `:` (colon), space, `,` (comma) | Reference operators | `A1:A3` | A range of cells |
| 2 | `-` | Negation (a minus sign in front of one value) | `=-5` | -5 |
| 3 | `%` | Percent | `=50%` | 0.5 |
| 4 | `^` | Exponent (power) | `=2^3` | 8 |
| 5 | `*` and `/` | Multiplication and division | `=6/3*2` | 4 |
| 6 | `+` and `-` | Addition and subtraction | `=1+2-3` | 0 |
| 7 | `&` | Joins text together | `="a"&"b"` | ab |
| 8 | `=` `<` `>` `<=` `>=` `<>` | Comparison | `=1+1=2` | TRUE |
Parentheses sit above this whole table. Anything inside parentheses is calculated first. The next chapter covers them in detail, so this chapter only uses them to confirm results.
For arithmetic formulas, you mostly need ranks 2 to 6:
- Negation and percent come first.
- Then
^. - Then
*and/, treated as equals. - Then
+and-, treated as equals.
The reference operators in rank 1 matter when you build ranges such as A1:A3. Excel resolves the range before any arithmetic touches it.
Walking through a formula step by step
To predict a result, rewrite the formula one operation at a time. Each rewrite replaces the part Excel calculates next with its value.
Take this formula:
=4+6/2*3- Division and multiplication outrank addition, so Excel handles
6/2*3first. /and*have equal rank, so Excel goes left to right. It calculates6/2, which is 3, and the formula becomes=4+3*3.- Next it calculates
3*3, which is 9, and the formula becomes=4+9. - Last, it adds: the result is 13.
Writing out these steps on paper is the most reliable way to check a formula you did not write yourself.
Equal rank means left to right
When two operators have the same rank, Excel calculates the leftmost one first. This rule has real consequences for subtraction and division, because those operations give different answers depending on grouping.
=10-4-3Excel calculates 10-4 first, which is 6, then 6-3. The result is 3. If it worked right to left, it would calculate 4-3 first and return 9.
=100/10/2Excel calculates 100/10, which is 10, then 10/2. The result is 5. Right to left would give 20.
The same rule applies when multiplication and division are mixed:
=12/3*2Excel divides first, because / is the leftmost operator. 12/3 is 4, and 4*2 is 8. A common mistake is to assume multiplication always goes first. That would give 3*2 = 6 and 12/6 = 2. Multiplication and division have equal rank, so position decides.
The same holds for addition and subtraction. =10-2+3 returns 11, because Excel subtracts first and then adds.
Negation comes before the exponent
Here is the place where Excel most often surprises people with a math background. Look at this formula:
=-2^2In a math class, -2² usually means "the negative of 2 squared", which is -4. Excel returns 4. Negation has a higher rank than ^, so Excel turns 2 into -2 first and then squares it: (-2)^2 = 4.
To get -4, tell Excel to square first:
=-(2^2)Now the parentheses force 2^2 to be calculated first, and the negation applies to the result, which is -4.
The same behavior applies to cell references. If A1 holds 3, then =-A1^2 returns 9, not -9.
Exponents also go left to right
Many people expect a chain of exponents to be calculated from the top down, so that 2^3^2 means 2^(3^2), which is 512. In Excel it does not. The ^ operator follows the same left-to-right rule as every other operator:
=2^3^2Excel calculates 2^3 first, which is 8, then 8^2. The result is 64.
If you want the other grouping, add parentheses:
=2^(3^2)This returns 512. Chained exponents are rare in everyday spreadsheets, but they show up in compound growth models, so it is worth knowing the rule.
Exponents before multiplication
Because ^ outranks * and /, a power is calculated before the multiplication or division next to it:
=2*3^2Excel calculates 3^2 first, which is 9, and then 2*9. The result is 18. If Excel multiplied first, 2*3 = 6 and 6^2 = 36.
In the same way, =8/2^2 returns 2, not 16. Excel calculates 2^2 = 4, then 8/4.
The percent operator
The % operator ranks above ^, *, /, +, and -. It divides the value immediately before it by 100. The later chapter on percentages and powers covers it in depth, but you need one precedence fact from it here: the percent sign is applied to its own number before anything else.
=10%*200Excel reads 10% as 0.1, then multiplies: the result is 20.
The percent sign applies only to the value directly in front of it, not to everything to its left. This matters in formulas that mix addition and percent:
=10+5%This returns 10.05, not 10.5. Excel converts 5% to 0.05 and then adds it to 10. It does not mean "10 plus 5 percent of 10". If you want 5 percent added to 10, you need a formula like =10*(1+5%), which returns 10.5.
Worked examples with cell references
Precedence rules apply to cell references exactly as they apply to typed numbers. Excel replaces each reference with the cell's value, then follows the same ranking.
Averaging three numbers
Suppose A1 holds 6, A2 holds 9, and A3 holds 12. A common first attempt at an average is:
=A1+A2+A3/3Excel divides first, so A3/3 is 4. Then it adds: 6+9+4 = 19. This is not the average. The correct formula groups the additions so they happen first:
=(A1+A2+A3)/3This adds to 27, then divides by 3 for an average of 9.
Adding tax to a line total
Suppose B2 holds a unit price of 50, C2 holds a quantity of 3, and F1 holds a tax rate of 8%. This formula adds tax to the line total:
=B2*C2*(1+$F$1)Excel calculates 1+$F$1 first, because it is in parentheses. That gives 1.08. Then it multiplies left to right: 50*3 = 150, and 150*1.08 = 162.
Now compare a version with the parentheses removed:
=B2*C2*1+$F$1Multiplication happens first, so B2*C2*1 is 150. Then Excel adds $F$1, which is 0.08. The result is 150.08. Excel does not report an error, and the number looks plausible, which makes this kind of mistake easy to miss. The cell shows a valid result, and it is the wrong one.
Comparison and text joining in the table
The last two rows of the precedence table are lower than all arithmetic, and they explain some results that look odd at first.
Because + outranks &, arithmetic is finished before text is joined:
=1+2&3Excel calculates 1+2 first, which is 3, and then joins it to the text "3". The result is the text 33, not 6 and not 15.
Comparison operators rank lowest, so both sides of a comparison are fully calculated first:
=2+3*4=14Excel calculates the left side, 2+3*4, which is 14, and then compares it with 14. The result is TRUE. Note that the second = here is a comparison operator and is different from the = that starts the formula.
Checking your prediction
Predicting a result and then comparing it with Excel's answer is a good way to build confidence. Use this routine:
- Underline the operators in the formula and mark each one with its rank from the table.
- Calculate the lowest-numbered rank first, left to right within a rank.
- Rewrite the formula after each step, as in the
=4+6/2*3example. - Compare your final value with what Excel shows after you press Enter.
When your answer and Excel's differ, find the first step where your rewrite and Excel's logic would diverge. It is usually one of three things:
- Multiplication assumed to outrank division.
- Negation assumed to come after an exponent.
- A percent sign assumed to apply to more than the number in front of it.
Excel also has a built-in tool that shows the calculation one step at a time. On the Formulas tab, choose Evaluate Formula and click Evaluate. Each click replaces the next piece with its value, in the same order as your hand calculation. A later chapter covers this tool and other ways to check a formula.
Summary of edge cases
| Formula | Result | Reason |
|---|---|---|
| `=2+3*4` | 14 | `*` outranks `+` |
| `=10-4-3` | 3 | Same rank, left to right |
| `=100/10/2` | 5 | Same rank, left to right |
| `=12/3*2` | 8 | `/` and `*` are equal, so left to right |
| `=-2^2` | 4 | Negation outranks `^` |
| `=-(2^2)` | -4 | Parentheses force the power first |
| `=2^3^2` | 64 | Exponents go left to right |
| `=2*3^2` | 18 | `^` outranks `*` |
| `=10+5%` | 10.05 | `%` applies only to the 5 |
| `=1+2&3` | 33 (text) | `+` outranks `&` |
Exercise
Without using Excel, calculate the result of =20-2*3^2/6. Write each rewrite step.
Show answer
Exponent first: 3^2 = 9, so the formula becomes =20-29/6. Then and / go left to right: 2*9 = 18, so =20-18/6, then 18/6 = 3, so =20-3. Last, subtraction gives 17.
Exercise
A1 holds 6, A2 holds 9, and A3 holds 12. A colleague wrote =A1+A2+A3/3 to find the average and got 19. Explain why, and write a corrected formula.
Show answer
Excel divides A3 by 3 first, because / outranks +. That gives 4, and 6+9+4 = 19. The corrected formula is =(A1+A2+A3)/3, which adds first and returns 9.
Exercise
What does =-2^2+10%*50 return, and what does each part contribute?
Show answer
It returns 9. Negation comes before the exponent, so -2^2 is (-2)^2 = 4. The percent is applied to 10 first, giving 0.1, and 0.1*50 = 5. Then 4+5 = 9.
Exercise
Why does =12/3*2 return 8 and not 2? How would you write a formula that returns 2?
Show answer
/ and have equal rank, so Excel goes left to right: 12/3 = 4, then 42 = 8. To get 2, group the denominator with parentheses: =12/(3*2).