MS-Excel / Functions and Formula

Understanding operator precedence in formulas

When Excel calculates the value of a formula, it uses certain rules to determine the order in which the various parts of the formula are calculated. You need to understand these rules if you want your formulas to produce the desired results.

Table shown below lists the Excel operator precedence. This table shows that exponentiation has the highest precedence (it's performed first) and logical comparisons have the lowest precedence (they are performed last).

SymbolOperatorPrecedence
^Exponentiation1
*Multiplication2
/Division2
+Addition3
-Subtraction3
&Concatenation4
=Equal to5
<Less than5
>Greater than5

You can use parentheses to override the Excel's built-in order of precedence. Expressions within parentheses are always evaluated first.

The following formula uses parentheses to control the order in which the calculations occur. In this case, cell B3 is subtracted from cell B2 and the result is multiplied by cell B4:

=(B2-B3)*B4

If you enter the formula without the parentheses, Excel computes a different answer. Because multiplication has a higher precedence, cell B3 is multiplied by cell B4. Then this result is subtracted from cell B2, which is not what was intended.

The formula without parentheses looks like this:

=B2-B3*B4

It's a good idea to use parentheses even when they are not strictly necessary. Doing so helps to clarify what the formula is intended to do. For example, the following formula makes it perfectly clear that B3 should be multiplied by B4, and the result subtracted from cell B2. Without the parentheses, you would need to remember Excel's order of precedence.

=B2-(B3*B4)

You can also nest parentheses within formulas-that is, put them inside other parentheses. If you do so, Excel evaluates the most deeply nested expressions first-and then works its way out. Here's an example of a formula that uses nested parentheses:

=((B2*C2)+(B3*C3)+(B4*C4))*B6

This formula has four sets of parentheses-three sets are nested inside the fourth set. Excel evaluates each nested set of parentheses and then sums the three results. This result is then multiplied by the value in B6.
Although the preceding formula uses four sets of parentheses, only the outer set is really necessary. If you understand operator precedence, it should be clear that you can rewrite this formula as:

=(B2*C2+B3*C3+B4*C4)*B6

Again, using the extra parentheses makes the calculation much clearer.

Every left parenthesis, of course, must have a matching right parenthesis. If you have many levels of nested parentheses, keeping them straight can sometimes be difficult. If the parentheses don't match, Excel displays a message explaining the problem-and won't let you enter the formula.

In some cases, if your formula contains mismatched parentheses, Excel may propose a correction to your formula. Figure shown below an example of the Formula AutoCorrect feature. You may be tempted simply to accept the proposed correction, but be careful-in many cases, the proposed formula, although syntactically correct, is not the formula you intended, and it will produce an incorrect result.

Excel's Formula AutoCorrect feature often suggests a correction to an erroneous formula.

Excel's Formula AutoCorrect Feature

Excel lends a hand in helping you match parentheses. When the insertion point moves over a parenthesis while you are editing a cell, Excel momentarily bolds it and does the same with its matching parenthesis.

[Previous] [Contents]