Using Brackets in formulas confusing me...

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, my current formula here in P3 is =IF(O3="",0,IF(O3*24>N3,0,(O3*24-((N3-(O3*24))*P2))))

Do you see any probem in this formula?


Thanks
Pedie
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You have more than you need ...

=IF(O3="", 0, IF(O3*24>N3, 0, O3*24-(N3*24-O3)*P2))

EDIT: It looks a little off, though, if the 24 is converting time values to decimal hours.
 
Last edited:
Upvote 0
You have more than you need ...
=IF(O3="", 0, IF(O3*24>N3, 0, O3*24-(N3*24-O3)*P2))

Hi Shg, does using brackets in a wrong way lead to wrong results?

My formula which is "=IF(O3="",0,IF(O3*24>N3,0,(O3*24-((N3-(O3*24))*P2))))" when changed to
=IF(O3="", 0, IF(O3*24>N3, 0, O3*24-(N3*24-O3)*P2))
gave me 2 different results
<TABLE style="WIDTH: 48pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=64><COLGROUP><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 48pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" height=20 width=64 align=right>0.132833</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" height=20 align=right>0.0255</TD></TR></TBODY></TABLE>
respectively.

Thanks again for helping.:)


PS: yes it is converting it to decimals...
 
Upvote 0
Eliminating the unnecessary parens, you can see that those two formulas are different.

This


=IF(O3="", 0, IF(O3*24>N3, 0, (O3*24 - ((N3-(O3*24))*P2))))

is exactly the same as

=IF(O3="", 0, IF(O3*24>N3, 0, O3*24 - (N3-O3*24)*P2))

which is not the same as

=IF(O3="", 0, IF(O3*24>N3, 0, O3*24 - (N3*24-O3)*P2))

Look at the difference in the expressions in the innermost parens.

EDIT:
... does using brackets in a wrong way lead to wrong results?

Well, it can:

2*3 + 4 = 10

2*(3+4) = 14

You could write the first expression as (2*3) + 4, but it's unnecessary.

Parens control the order of evaluation when Excel's standard operator precedence doesn't do what you want. Your parens were unnecessary because Excel was already going to evaluate the expression the way that the additional parens indicated.
 
Last edited:
Upvote 0
Thanks again Shg! so which one do i use now?

Do i use this "=IF(O3="", 0, IF(O3*24>N3, 0, O3*24 - (N3-O3*24)*P2))"?

Thanks again:)
 
Upvote 0
Dunno, pedie, what's the formula supposed to do?
 
Upvote 0
Dunno, pedie, what's the formula supposed to do?

I'm actually practicing how to handly this kind of formula which has lots of brackets required....
In this scenario...'m trying to check if target is met by an employee which is 0.15 or 9mins. if task is not completed within 9 mins then 0 points else target-(score * 24)-target)) * yeild :).
I hope i make some sense...:(

Thanks again!
 
Upvote 0
now 'm using formula with a named range as
=IF(Score="",0,IF(Score*24>Target,0,Score*24-(Target-Score*24)*E1))
 
Upvote 0
If it gives the answer you want, it's the right formula.

The place to start is to understand Excel's operators and operator precedence, which is, from highest to lowest,
Reference (i.e., the colon in SUM(A1:B1), the comma in SUM(A1, C1), the space in SUM(A1:C3 B1:B5))

Unary negation -3^2

Percentage %

Exponentiation 3^2

Multiplication and Division * /

Catenation &

Comparison < <= >= > = <>
Excel evaluates left to right for operators of equal precedence.

If you want precedence different than that, you use parens.
 
Last edited:
Upvote 0
Thanks again Shg for cleaing things for me....'l try to look more deep in to it and keep these things in mind.

Appriciate your help.:)
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top