• 469K Members
• 4,518 Online
• 567K Conversations

## A case of wrong formula calculation in Excel?

Occasional Contributor

# A case of wrong formula calculation in Excel?

I like to have your opinion on the formula calculation performed by Excel in a particolar case that surprised me very much.
This is the case.
A(1,1) =5
A(2,1) = - A1^2
Excel display result in A(2,1) = +25, that is wrong. Te correct result must be -25 because the sign “-“ in not under the square elevation.
I modified the formula in this way:
A(2,1) = - A1^2 + A1
The result is = 30 that is wrong again!
The I changed the order of the two addendum
A(2,1) = A1 - A1^2
Now the result is -20 and, that is correct.
Regards and thank.

5 Replies
Highlighted

# Re: A case of wrong formula calculation in Excel?

Check the order of operation with formula evaluation.

-A1^2 -> -5 -> -5^2 -> 25

-(A1^2) -> -(5^2) -> -(25) -> -25

# Re: A case of wrong formula calculation in Excel?

@Detlef Lewin

The help page shows the operator precedence to be as shown in the following table.

If in doubt, a pair of parentheses work wonders!

 Operator Description : (colon)(single space), (comma) Reference operators – Negation (as in –1) % Percent ^ Exponentiation * and / Multiplication and division + and – Addition and subtraction & Connects two strings of text (concatenation) =< ><=>=<> Comparison

# Re: A case of wrong formula calculation in Excel?

What you says is clear but it's not correct because in the formula y=-x^2 the result is always negative for any x different from zero.
I don't have to use the parenthesis.
As I shown in the example, the same formula y= -A^2 +A =+A- A^2 is written in two different way, only changing the position af the two addendum. The result must be exactly the same. But this not what Excel does.
This means that it necessary to put attention at the order of the addendum in a sum, and this violates the commuted property of the terms of the sum.
Because now I know this question I put always attention when i write a formula, but in a complex problem this not simple and reliable.

# Re: A case of wrong formula calculation in Excel?

*

@SergioSolimena wrote:
As I shown in the example, the same formula y= -A^2 +A =+A- A^2 is written in two different way, only changing the position af the two addendum. The result must be exactly the same. But this not what Excel does.
*

As you can see in the table provided by @Peter Bartholomew the - (minus sign) in the first case is a negation (a lower order then ^) and in the second case a subtraction (a higher order then ^).

So by putting parenthesis around A^2 you are changing the order of operation:

-(A^2)+A = +A-(A^2)

# Re: A case of wrong formula calculation in Excel?

@Detlef Lewin wrote:
As you can see in the table provided by @Peter Bartholomew the - (minus sign) in the first case is a negation (a lower order then ^) and in the second case a subtraction (a higher order then ^.
-
The Excel rules are clear but unfortunately they are different, in this particular case, from the mathematical rules. This can generate an unexpected result and you have to be careful.
Thanks again.
Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
30 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies