For my new formula i need the following: If the contents of cell f6 = 1,
4
or 5 I need a specfic percentage added to that cell and a specific
rounding
rule applied. I have one excel file for rules 4 and 5 and a second file
for
rule 1 now i need one file for all 3 rules; if none of those rules exist
cell
f6 stays the same.
A quick-and-dirty solution might lie in finding ways to reduce the nesting
level.
(A better solution might lie in understanding your rounding rules and
finding some simplfication in the overall algorithm, if any. But that would
require in-depth knowledge of what you must do. I'm not going there.)
Caveat: I have not actually tried the following myself. It will reduce the
nesting level. According to my prototype, it should be enough; but I do not
know for sure. Nonetheless, it might be worth a try.
The overall structure of the combined formula is ostensibly:
=if(H6="4", ..., if(H6="3", ..., if(H6="1", ..., $J6)))
That could be written:
=if(and(H6<>{"1","3","4"}), $J6, choose(H6, ..., 0, ..., ...))
Note that the nesting level is reduced by one.
FYI, because of the AND() pre-condition, CHOOSE will never see H6=2. The
zero is just a place holder.
Another simpflication lies in avoiding over-specification in your
subordinate conditional expressions. Not only will this reduce the nesting
level by one again, but also it will avoid discontinuities: holes in the
logic that might exist due to rounding or numerical anomalies associated
with numbers with decimal fractions.
Specifically:
1. Change:
IF($J6<=50, ...,
IF(AND($J6>=50.01,$J6<=100), ...,
IF(AND($J6>100.01,$J6<=500), ...,
IF($J6>=500.01, CHOOSE(...), ""))))
to:
IF($J6<=50, ..., IF($J6<=100, ..., IF($J6<=500, ..., CHOOSE(...))))
2. Change:
IF($J6<=1, ...,
IF(AND($J6>1,$J6<=1.05), ...,
IF(AND($J6>=1.06,$J6<=1.09), ...,
IF(AND($J6>=1.1,$J6<=9.99), ...,
IF($J6>=10, CEILING($J6+0.01,0.5)-0.01)))))
to:
IF($J6<=1, ..., IF($J6<1.06, ..., IF($J6<1.1, ..., IF($J6<10, ...,
CEILING(...)-0.01))))
Note: I took the liberty of presuming the correction in the errata
below.
Caveat: The preceding assumes that J6 is explicitly rounded to 2 decimal
places, not merely formatted as such. If that's not the case (explicit
rounding), more tweaks to your algorithm might be desirable, depending on
your tolerance.
Errata ....
You worte:
the second formula i have tested all possible results and my
answers are all correct.
I believe I see your intent now. I still believe there is an error in the
nesting of IF() functions; but it is not the error that I first thought.
I am still puzzled by the structure of your second formula. I believe there
is an error starting at:
IF(AND($J6>=1.1,$J6<=9.99)+IF(RIGHT((ROUNDUP(...))*100,1)="0", ...
I could be wrong. To follow along, I suggest that you copy-and-paste the
formula into Notepad, break it down so that IF(condition,truePart,falsePart)
is on separate lines, and number the parentheses of nesting levels like
this: IF1(...)1.
The following is what I see (with apologies if things do not align as
intended):
=IF1($H6=1,
IF2($J6<=1, $J6,
IF3(AND($J6>1,$J6<=1.05), 0.99,
IF4(AND($J6>=1.06,$J6<=1.09), 1.09,
IF5(AND($J6>=1.1,$J6<=9.99)
+IF6(RIGHT((ROUNDUP($J6,2))*100,1)="0", ROUNDUP($J6,1)+0.09,
IF7(RIGHT($J6,2)*100<=9, 19,
(ROUNDUP($J6*100,-1)-1)/100)7)6,
IF6($J6>=10,CEILING($J6+0.01,0.5)-0.01)6)5)4)3)2,
$F6)1
Note that the expression IF($J6>=10,...) is the true part of the expression
IF(AND($J6>=1.1,$J6<=9.99)+IF(...),...).
If that is your intent, then I believe "IF5" will return FALSE when
$J6<=9.99, as I said before. Explanation....
The expression AND(...)+IF(...) behaves like an OR operation: it is false
only when both functions return false or zero. But I believe the "+IF(...)"
expression is always greater than zero. So I believe AND(...)+IF(...) is
always true, even when $J6<=9.99. Thus, when $J6<=9.99, IF($J6>=10,...) is
false. And since there is no false part, it will return FALSE.
Moreover, if my analysis is correct, then as written, I do not believe "IF5"
behaves at all as you intended. I suspect it should return 19 or either of
the ROUNDUP results. I believe it does not.
I suspect that your original intent was for "+IF(...)" to be ",IF(...)";
that is, it is intended to be the true part when 1.1<=$J6<=9.99. I suspect
the formula got mangled in an attempt to solve a problem with too many
nesting levels, taking RIGHT(ROUND(...)...) into account.
Forgive me if I am wrong, and this is a red herring.
But if my analysis is correct, then with the simplification that I suggested
above, you might be able to correct this by reverting back to ",IF(...)"
instead of "+IF(...)". However, if you do, I suspect you will encounter
nesting level problems in the combined IF() expression, despite my
suggestions. Sigh.
----- original message -----