Link to home
Start Free TrialLog in
Avatar of navaqeel
navaqeel

asked on

Excel - Order of Precedence

Hello:

Can anyone please explain or help?  I enter following formula in Excel:

=B5*B6+C3/D4^2

According to the order of precedence, it's supposed to calculate or evaluate the exponent D4^2 first but it's not doing that.  It first calculates B5*B6 and then it calculates the exponent and then it divides C3 by the result of D4^2 and finally adds.  

Can anyone please suggest why Excel's doing this?  

SOLUTION
Avatar of AdamRobinson
AdamRobinson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AdamRobinson
AdamRobinson

If so, you should probably try: (C3 /  D4)^2

Otherwise, after re-reading what you wrote 10 times now, I can't see how it is doing anything wrong.  
Avatar of b0lsc0tt
navaqeel,

Actually it is handling the exponent first.  It just isn't part of the B5*B6.  The exponent is involved in the part C3/D4^2.  It is done before the division as you mentioned.  Once all of this is done then the addition is done.

This page (http://www.informit.com/articles/article.asp?p=328639&seqNum=2&rl=1) has a nice table that shows the order.

Let me know if you have any questions or need more information.

b0lsc0tt
AdamRobinson may have answered all of your question.  My post has some different info but is pretty much a late duplicate.  If you are watching Excel do this step by step then and question that then it is the rule of working left to right.  If the exponent was with B5*B6 then it would have been done before the multiplication.

bol
Avatar of navaqeel

ASKER

Thanks for all suggestions guys.  when i evaluate this formula using the "Evaluate Formula" button on the Auditing tool bar, it clearly displays that the multiplication between B5 * B6 takes place first, then the exponent D4^2 gets evaluated then the division and finally the addition.  

Try this out yourself.  Enter some numbers in B5, B6, C3, and D4 and then type the following expression as it is:

=B5*B6+C3/D4^2

No parenthesis have to be applied in the above formula.  I just can't understand why B5*B6 gets evaluated first.  
Try this too:

=B5*B6+C3/B5+D4^2

In the above expression, the exponent will be calculated at the end even after addition. Is something wrong with my Excel ???
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In mathematics the basic principle of "BODMAS" is applied.
This should also transfer to Excel.

BODMAS defines the order of what is carried out.

B - brackets
O - order (or exponent)
D - division
M - multiplication
A - addition
S - subtraction

for example - what is 2 + 3 x 5?

Apply the left to right rule - gives 25. Incorrect.
Apply BODMAS gives 17. Correct.
Try it in excel.

Here's a link
http://www.easymaths.com/What_on_earth_is_Bodmas.htm
So transferring to your equation  "=B5*B6+C3/B5+D4^2"
(e.g. - B5=3,  B6=8,  C3=6, D4=2)
gives us

D4^2  = 4
C3/B5  = 2
B5*B6  = 24

all added up = 30
I should have realized you were just asking theoretically.  The reason the formula does this was addressed by b0l above.  Excel does make assumptions about multiplication and parentheses.  The simple reason is there is no substantive difference between:

a * b and (a * b)

The better reason for doing so (keeping it mind it operates left to right!) is because

(a * b) + (c * d ^ 4)

really does need parentheses around the first part in order to be clearer.  In your case, it's not as big of a deal, but think of this.

(a * b) + (b + a + c / 4) - (d + e + f) + (g) + (h+a)

Without the parentheses, a human might begin to stare there.  Excel, IIRC, can provide parentheses' suggestions.  Given this is the case, it likely is just built in to assume parentheses exist for the human using the program.  

@SeriousNick - I may not have been clear enough when I tried to answer the question and mentioned Excel was working from left to right.  What I meant to describe still looks at the signs to calculate.  In your example (2 + 3 * 5) it would see the multiplication sign, as it moved from left to right, and not calculate, since the precedence was higher.  The calculation would be correct.  The method my comment described would not yield 25.  I'm sorry if that wasn't clear in what I typed and thanks for giving me a chance to clarify it.

bol
Hi bol

Thats great.
I was simply mentioning the acronym BODMAS (which is taught at elementary levels of education) contrary to popular belief that one should calculate from the left first.
This "rule" has been adapted by electronic calculations too, and therefore is the basic principle used when a formula/equation has been poorly written (without parentheses for example).
Regardless of how Excel "appears" to be doing the calculations - it should always follow the above priniciple.
It works for kids of a very young age and can still work for us "older" folks......  Simple to remember (which becomes so much more helpful as time ticks by ...).

No offence intended whatsoever so hopefully none taken.  :)

Although, in re-reading, I have to admit >>"The key is probably to remember that working left to right is the first rule."<< in your post was misleading so glad we had a chance to clarify the position on that.

And now I think the questioner has more than enough information.  ;)

Regards to all!!
I'm glad that I could be one of those that helped you.  Thank you for the grade, the points and the fun question.

bol