Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 98
Default More than 16 nested IFs!!!!

Hi all,

I used Chip Pearsons method of overcoming 7 nested IF statements using named
ranges and this worked (http://www.cpearson.com/excel/nested.htm) but now I
have some additions to my formula which makes the total number of IFs 16 -
how do I get over more than 7 IFs in each of my seperate named ranges???

Here is my whole formula!!! It calculates the lowest margin for a range of
selling prices. P and R are new and old standard costs (I need to use R in
the calculation if P is 0), the rest of the cells are 4 different prices
volume breaks, the lowest of which needs to be used in the calculation. To
make matters worse there is a new and old column for each price break and
obviously I need to use the new but revert back to using the old if no new
price is entered! Hence my 16 IFs!!!

=
IF(AND($P20,$AA20),((($AA2-$P2))/$AA2),IF(AND($P2=0,$AA20),((($AA2-$Q2))/$AA2),IF(AND($P20,$AJ20),((($AJ2-$P2))/$AJ2),IF(AND($P2=0,$AJ20),((($AJ2-$Q2))/$AJ2),IF(AND($P20,$AS20),((($AS2-$P2))/$AS2),IF(AND($P2=0,$AS20),((($AS2-$Q2))/$AS2),IF(AND($P20,$BB20),((($BB2-$P2))/$BB2),IF(AND($P2=0,$BB20),((($BB2-$Q2))/$BB2),IF(AND($P20,$X20,$AG20,$AP20,$AY20),((( $AY2-$P2))/$AY2),IF(AND($P20,$X20,$AG20,$AP20,$AY2=0),((( $AP2-$P2))/$AP2),IF(AND,($P20,$X20,$AG20,$AP2=0,$AY2=0),(( ($AG2-$P2))/$AG2),IF(AND($P20,$X20,$AG2=0,$AP2=0,$AY2=0),((( $X2-$P2))/$X2),IF(AND($P2=0,$X20,$AG20,$AP20,$AY20),((($ AY2-$Q2))/$AY2),IF(AND($P2=0,$X20,$AG20,$AP20,$AY2=0),((( $AP2-$Q2))/$AP2),IF(AND($P2=0,$X20,$AG20,$AP2=0,$AY2=0),((( $AG2-$Q2))/$AG2),IF(AND($P2=0,$X20,$AG2=0,$AP2=0,$AY2=0),((( $X2-$Q2))/$X2),0))))))))))))))))


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 733
Default More than 16 nested IFs!!!!

Meltad wrote...
....
Here is my whole formula!!! It calculates the lowest margin for a range of
selling prices. P and R are new and old standard costs (I need to use R in
the calculation if P is 0), the rest of the cells are 4 different prices
volume breaks, the lowest of which needs to be used in the calculation. To
make matters worse there is a new and old column for each price break and
obviously I need to use the new but revert back to using the old if no new
price is entered! Hence my 16 IFs!!!


[reformatted]
=IF(AND($P20,$AA20),
((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),
((($AA2-$Q2))/$AA2),
IF(AND($P20,$AJ20),
((($AJ2-$P2))/$AJ2),
IF(AND($P2=0,$AJ20),
((($AJ2-$Q2))/$AJ2),
IF(AND($P20,$AS20),
((($AS2-$P2))/$AS2),
IF(AND($P2=0,$AS20),
((($AS2-$Q2))/$AS2),
IF(AND($P20,$BB20),
((($BB2-$P2))/$BB2),
IF(AND($P2=0,$BB20),
((($BB2-$Q2))/$BB2),
IF(AND($P20,$X20,$AG20,$AP20,$AY20),
((($AY2-$P2))/$AY2),
IF(AND($P20,$X20,$AG20,$AP20,$AY2=0),
((($AP2-$P2))/$AP2),
IF(AND,($P20,$X20,$AG20,$AP2=0,$AY2=0),
((($AG2-$P2))/$AG2),
IF(AND($P20,$X20,$AG2=0,$AP2=0,$AY2=0),
((($X2-$P2))/$X2),
IF(AND($P2=0,$X20,$AG20,$AP20,$AY20),
((($AY2-$Q2))/$AY2),
IF(AND($P2=0,$X20,$AG20,$AP20,$AY2=0),
((($AP2-$Q2))/$AP2),
IF(AND($P2=0,$X20,$AG20,$AP2=0,$AY2=0),
((($AG2-$Q2))/$AG2),
IF(AND($P2=0,$X20,$AG2=0,$AP2=0,$AY2=0),
((($X2-$Q2))/$X2),
0
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)


All conditions check either P20 or P2=0. If P2<0, the result will
always be 0. If P20, use P2 in the result expression; otherwise, if
P2=0, use Q2 in the result expression. Which means that the result
expression could be rewritten [simplifying (((a-x))/a) to 1-x/a] as

1-IF($P20,$P2,$Q2)/a

The rest of the logic decides what <a should be. It's either the first
positive value in AA2, AJ2, AS2, BB2, or if none of them are positive,
the last positive value in X2, AG2, AP2, AY2, or if none of them are
positive, 0.

So the result is zero if either P2<0 or none of X2, AA2, AG2, AJ2, AP2,
AS2, AY2, BB2 are positive. That can be expressed as

=IF(OR($P2<0,NOT(OR(X20,AA20,AG20,AJ20,AP20,A S20,AY20,BB20))),0,...)

Finding the intended positive value can be done with some trickery
using LOOKUP and OFFSET.

LOOKUP(2,1/(N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))0),
N(OFFSET($X2,0,{0,9,18,27,30,21,12,3})))

The trick here being that LOOKUP will return values in order from RIGHT
to LEFT, so the value you want first if it's positive is the rightmost
one referenced by OFFSET (the 3 in the array constant, or cell AA2),
and the one you want last if it's the only one of them that's positive
is the leftmost one referenced by OFFSET (the 0 in the array constant,
or cell X2).

Tie it all together.

=IF(OR($P2<0,NOT(OR(X20,AA20,AG20,AJ20,AP20,A S20,AY20,BB20))),0,
1-IF($P20,$P2,$Q2)/LOOKUP(2,1/(N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))0),
N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))))

Any complicated nested IF construct can be reduced to a lookup,
possibly with even less clarity, but definitely with fewer nested
function call levels.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 98
Default More than 16 nested IFs!!!!

Wow what a reply! Thanks Harlan I'll try this out on Monday and let you know
how it goes.

"Harlan Grove" wrote:

Meltad wrote...
....
Here is my whole formula!!! It calculates the lowest margin for a range of
selling prices. P and R are new and old standard costs (I need to use R in
the calculation if P is 0), the rest of the cells are 4 different prices
volume breaks, the lowest of which needs to be used in the calculation. To
make matters worse there is a new and old column for each price break and
obviously I need to use the new but revert back to using the old if no new
price is entered! Hence my 16 IFs!!!


[reformatted]
=IF(AND($P20,$AA20),
((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),
((($AA2-$Q2))/$AA2),
IF(AND($P20,$AJ20),
((($AJ2-$P2))/$AJ2),
IF(AND($P2=0,$AJ20),
((($AJ2-$Q2))/$AJ2),
IF(AND($P20,$AS20),
((($AS2-$P2))/$AS2),
IF(AND($P2=0,$AS20),
((($AS2-$Q2))/$AS2),
IF(AND($P20,$BB20),
((($BB2-$P2))/$BB2),
IF(AND($P2=0,$BB20),
((($BB2-$Q2))/$BB2),
IF(AND($P20,$X20,$AG20,$AP20,$AY20),
((($AY2-$P2))/$AY2),
IF(AND($P20,$X20,$AG20,$AP20,$AY2=0),
((($AP2-$P2))/$AP2),
IF(AND,($P20,$X20,$AG20,$AP2=0,$AY2=0),
((($AG2-$P2))/$AG2),
IF(AND($P20,$X20,$AG2=0,$AP2=0,$AY2=0),
((($X2-$P2))/$X2),
IF(AND($P2=0,$X20,$AG20,$AP20,$AY20),
((($AY2-$Q2))/$AY2),
IF(AND($P2=0,$X20,$AG20,$AP20,$AY2=0),
((($AP2-$Q2))/$AP2),
IF(AND($P2=0,$X20,$AG20,$AP2=0,$AY2=0),
((($AG2-$Q2))/$AG2),
IF(AND($P2=0,$X20,$AG2=0,$AP2=0,$AY2=0),
((($X2-$Q2))/$X2),
0
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)


All conditions check either P20 or P2=0. If P2<0, the result will
always be 0. If P20, use P2 in the result expression; otherwise, if
P2=0, use Q2 in the result expression. Which means that the result
expression could be rewritten [simplifying (((a-x))/a) to 1-x/a] as

1-IF($P20,$P2,$Q2)/a

The rest of the logic decides what <a should be. It's either the first
positive value in AA2, AJ2, AS2, BB2, or if none of them are positive,
the last positive value in X2, AG2, AP2, AY2, or if none of them are
positive, 0.

So the result is zero if either P2<0 or none of X2, AA2, AG2, AJ2, AP2,
AS2, AY2, BB2 are positive. That can be expressed as

=IF(OR($P2<0,NOT(OR(X20,AA20,AG20,AJ20,AP20,A S20,AY20,BB20))),0,...)

Finding the intended positive value can be done with some trickery
using LOOKUP and OFFSET.

LOOKUP(2,1/(N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))0),
N(OFFSET($X2,0,{0,9,18,27,30,21,12,3})))

The trick here being that LOOKUP will return values in order from RIGHT
to LEFT, so the value you want first if it's positive is the rightmost
one referenced by OFFSET (the 3 in the array constant, or cell AA2),
and the one you want last if it's the only one of them that's positive
is the leftmost one referenced by OFFSET (the 0 in the array constant,
or cell X2).

Tie it all together.

=IF(OR($P2<0,NOT(OR(X20,AA20,AG20,AJ20,AP20,A S20,AY20,BB20))),0,
1-IF($P20,$P2,$Q2)/LOOKUP(2,1/(N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))0),
N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))))

Any complicated nested IF construct can be reduced to a lookup,
possibly with even less clarity, but definitely with fewer nested
function call levels.


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 98
Default More than 16 nested IFs!!!!

Thanks Harlan, this works perfectly! Just what I was after, and thanks for
all the explanation aswell :-)


"Harlan Grove" wrote:

Meltad wrote...
....
Here is my whole formula!!! It calculates the lowest margin for a range of
selling prices. P and R are new and old standard costs (I need to use R in
the calculation if P is 0), the rest of the cells are 4 different prices
volume breaks, the lowest of which needs to be used in the calculation. To
make matters worse there is a new and old column for each price break and
obviously I need to use the new but revert back to using the old if no new
price is entered! Hence my 16 IFs!!!


[reformatted]
=IF(AND($P20,$AA20),
((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),
((($AA2-$Q2))/$AA2),
IF(AND($P20,$AJ20),
((($AJ2-$P2))/$AJ2),
IF(AND($P2=0,$AJ20),
((($AJ2-$Q2))/$AJ2),
IF(AND($P20,$AS20),
((($AS2-$P2))/$AS2),
IF(AND($P2=0,$AS20),
((($AS2-$Q2))/$AS2),
IF(AND($P20,$BB20),
((($BB2-$P2))/$BB2),
IF(AND($P2=0,$BB20),
((($BB2-$Q2))/$BB2),
IF(AND($P20,$X20,$AG20,$AP20,$AY20),
((($AY2-$P2))/$AY2),
IF(AND($P20,$X20,$AG20,$AP20,$AY2=0),
((($AP2-$P2))/$AP2),
IF(AND,($P20,$X20,$AG20,$AP2=0,$AY2=0),
((($AG2-$P2))/$AG2),
IF(AND($P20,$X20,$AG2=0,$AP2=0,$AY2=0),
((($X2-$P2))/$X2),
IF(AND($P2=0,$X20,$AG20,$AP20,$AY20),
((($AY2-$Q2))/$AY2),
IF(AND($P2=0,$X20,$AG20,$AP20,$AY2=0),
((($AP2-$Q2))/$AP2),
IF(AND($P2=0,$X20,$AG20,$AP2=0,$AY2=0),
((($AG2-$Q2))/$AG2),
IF(AND($P2=0,$X20,$AG2=0,$AP2=0,$AY2=0),
((($X2-$Q2))/$X2),
0
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)


All conditions check either P20 or P2=0. If P2<0, the result will
always be 0. If P20, use P2 in the result expression; otherwise, if
P2=0, use Q2 in the result expression. Which means that the result
expression could be rewritten [simplifying (((a-x))/a) to 1-x/a] as

1-IF($P20,$P2,$Q2)/a

The rest of the logic decides what <a should be. It's either the first
positive value in AA2, AJ2, AS2, BB2, or if none of them are positive,
the last positive value in X2, AG2, AP2, AY2, or if none of them are
positive, 0.

So the result is zero if either P2<0 or none of X2, AA2, AG2, AJ2, AP2,
AS2, AY2, BB2 are positive. That can be expressed as

=IF(OR($P2<0,NOT(OR(X20,AA20,AG20,AJ20,AP20,A S20,AY20,BB20))),0,...)

Finding the intended positive value can be done with some trickery
using LOOKUP and OFFSET.

LOOKUP(2,1/(N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))0),
N(OFFSET($X2,0,{0,9,18,27,30,21,12,3})))

The trick here being that LOOKUP will return values in order from RIGHT
to LEFT, so the value you want first if it's positive is the rightmost
one referenced by OFFSET (the 3 in the array constant, or cell AA2),
and the one you want last if it's the only one of them that's positive
is the leftmost one referenced by OFFSET (the 0 in the array constant,
or cell X2).

Tie it all together.

=IF(OR($P2<0,NOT(OR(X20,AA20,AG20,AJ20,AP20,A S20,AY20,BB20))),0,
1-IF($P20,$P2,$Q2)/LOOKUP(2,1/(N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))0),
N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))))

Any complicated nested IF construct can be reduced to a lookup,
possibly with even less clarity, but definitely with fewer nested
function call levels.


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 98
Default More than 16 nested IFs!!!!

WAIT!!! I've just tested this a bit more thouroughly...

If a new selling price is entered when the selling price for that price
break was previously 0, then the lowest selling price still shows as the
previous price break (it goes back too far from right to left)...

EG If X20 and AA20, AG2=0 and AJ20, lowest margin is displayed as value
in AA2 but should be AJ2

Can we alter this formula to pick up the first number in the specified cells
working right to left (or is that what we are supposed to have?)





"Meltad" wrote:

Thanks Harlan, this works perfectly! Just what I was after, and thanks for
all the explanation aswell :-)


"Harlan Grove" wrote:

Meltad wrote...
....
Here is my whole formula!!! It calculates the lowest margin for a range of
selling prices. P and R are new and old standard costs (I need to use R in
the calculation if P is 0), the rest of the cells are 4 different prices
volume breaks, the lowest of which needs to be used in the calculation. To
make matters worse there is a new and old column for each price break and
obviously I need to use the new but revert back to using the old if no new
price is entered! Hence my 16 IFs!!!


[reformatted]
=IF(AND($P20,$AA20),
((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),
((($AA2-$Q2))/$AA2),
IF(AND($P20,$AJ20),
((($AJ2-$P2))/$AJ2),
IF(AND($P2=0,$AJ20),
((($AJ2-$Q2))/$AJ2),
IF(AND($P20,$AS20),
((($AS2-$P2))/$AS2),
IF(AND($P2=0,$AS20),
((($AS2-$Q2))/$AS2),
IF(AND($P20,$BB20),
((($BB2-$P2))/$BB2),
IF(AND($P2=0,$BB20),
((($BB2-$Q2))/$BB2),
IF(AND($P20,$X20,$AG20,$AP20,$AY20),
((($AY2-$P2))/$AY2),
IF(AND($P20,$X20,$AG20,$AP20,$AY2=0),
((($AP2-$P2))/$AP2),
IF(AND,($P20,$X20,$AG20,$AP2=0,$AY2=0),
((($AG2-$P2))/$AG2),
IF(AND($P20,$X20,$AG2=0,$AP2=0,$AY2=0),
((($X2-$P2))/$X2),
IF(AND($P2=0,$X20,$AG20,$AP20,$AY20),
((($AY2-$Q2))/$AY2),
IF(AND($P2=0,$X20,$AG20,$AP20,$AY2=0),
((($AP2-$Q2))/$AP2),
IF(AND($P2=0,$X20,$AG20,$AP2=0,$AY2=0),
((($AG2-$Q2))/$AG2),
IF(AND($P2=0,$X20,$AG2=0,$AP2=0,$AY2=0),
((($X2-$Q2))/$X2),
0
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)


All conditions check either P20 or P2=0. If P2<0, the result will
always be 0. If P20, use P2 in the result expression; otherwise, if
P2=0, use Q2 in the result expression. Which means that the result
expression could be rewritten [simplifying (((a-x))/a) to 1-x/a] as

1-IF($P20,$P2,$Q2)/a

The rest of the logic decides what <a should be. It's either the first
positive value in AA2, AJ2, AS2, BB2, or if none of them are positive,
the last positive value in X2, AG2, AP2, AY2, or if none of them are
positive, 0.

So the result is zero if either P2<0 or none of X2, AA2, AG2, AJ2, AP2,
AS2, AY2, BB2 are positive. That can be expressed as

=IF(OR($P2<0,NOT(OR(X20,AA20,AG20,AJ20,AP20,A S20,AY20,BB20))),0,...)

Finding the intended positive value can be done with some trickery
using LOOKUP and OFFSET.

LOOKUP(2,1/(N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))0),
N(OFFSET($X2,0,{0,9,18,27,30,21,12,3})))

The trick here being that LOOKUP will return values in order from RIGHT
to LEFT, so the value you want first if it's positive is the rightmost
one referenced by OFFSET (the 3 in the array constant, or cell AA2),
and the one you want last if it's the only one of them that's positive
is the leftmost one referenced by OFFSET (the 0 in the array constant,
or cell X2).

Tie it all together.

=IF(OR($P2<0,NOT(OR(X20,AA20,AG20,AJ20,AP20,A S20,AY20,BB20))),0,
1-IF($P20,$P2,$Q2)/LOOKUP(2,1/(N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))0),
N(OFFSET($X2,0,{0,9,18,27,30,21,12,3}))))

Any complicated nested IF construct can be reduced to a lookup,
possibly with even less clarity, but definitely with fewer nested
function call levels.




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 733
Default More than 16 nested IFs!!!!

Meltad wrote...
....
EG If X20 and AA20, AG2=0 and AJ20, lowest margin is displayed as value
in AA2 but should be AJ2

....

My formula would use AA2 in this case because *YOUR* original formula
would use AA2 in this case. That is, *YOUR* original formula begins

=IF(AND($P20,$AA20),
((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),
((($AA2-$Q2))/$AA2),

If AA20, your original formula wouldn't check whether any other value
in cells X2, AG2, AJ2, AP2, AS2, AY5, BB2 is greater than zero or not.
If that's not what you intended, then your original formula was wrong,
and you need to provide corrected specs.

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 98
Default More than 16 nested IFs!!!!

Hi Harlan,
You're right, I think I've got the order wrong...
I need to do the calculation using firstly P or then Q if P=0.
And to use the first value from right to left in the cells BB, AY, AS, AP,
AJ, AG, AA, X to do the rest of the calculation. Here are the corrected IFs
(I think!!)...

=
IF(AND($P20,$BB20),((($BB2-$P2))/BB2),
IF(AND($P2=0,$BB20),((($BB2-$Q2))/$BB2),
IF(AND($P20,$AY20),((($AY2-$P2))/$AY2),
IF(AND($P2=0,$AY20),((($AY2-$Q2))/$AY2),
IF(AND($P20,$AS20),((($AS2-$P2))/$AS2),
IF(AND($P2=0,$AS20),((($AS2-$Q2))/$AS2),
IF(AND($P20,$AP20),((($AP2-$P2))/$AP2),
IF(AND($P2=0,$AP20),((($AP2-$Q2))/$AP2),
IF(AND($P20,$AJ20),((($AJ2-$P2))/$AJ2),
IF(AND($P2=0,$AJ20),((($AJ2-$Q2))/$AJ2),
IF(AND($P20,$AG20),((($AG2-$P2))/$AG2),
IF(AND($P2=0,$AG20),((($AG2-$Q2))/$AG2),
IF(AND($P20,$AA20),((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),((($AA2-$Q2))/$AA2),
IF(AND($P20,$X20),((($X2-$P2))/$X2),
IF(AND($P2=0,$X20),((($X2-$Q2))/$X2),0))))))))))))))))



"Harlan Grove" wrote:

Meltad wrote...
....
EG If X20 and AA20, AG2=0 and AJ20, lowest margin is displayed as value
in AA2 but should be AJ2

....

My formula would use AA2 in this case because *YOUR* original formula
would use AA2 in this case. That is, *YOUR* original formula begins

=IF(AND($P20,$AA20),
((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),
((($AA2-$Q2))/$AA2),

If AA20, your original formula wouldn't check whether any other value
in cells X2, AG2, AJ2, AP2, AS2, AY5, BB2 is greater than zero or not.
If that's not what you intended, then your original formula was wrong,
and you need to provide corrected specs.


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 733
Default More than 16 nested IFs!!!!

Meltad wrote...
....
I need to do the calculation using firstly P or then Q if P=0.
And to use the first value from right to left in the cells BB, AY, AS, AP,
AJ, AG, AA, X to do the rest of the calculation. Here are the corrected IFs

....
[reformatted]
IF(AND($P20,$BB20),
((($BB2-$P2))/BB2),
IF(AND($P2=0,$BB20),
((($BB2-$Q2))/$BB2),
IF(AND($P20,$AY20),
((($AY2-$P2))/$AY2),

....
IF(AND($P2=0,$AY20),((($AY2-$Q2))/$AY2),
IF(AND($P20,$AS20),((($AS2-$P2))/$AS2),
IF(AND($P2=0,$AS20),((($AS2-$Q2))/$AS2),
IF(AND($P20,$AP20),((($AP2-$P2))/$AP2),
IF(AND($P2=0,$AP20),((($AP2-$Q2))/$AP2),
IF(AND($P20,$AJ20),((($AJ2-$P2))/$AJ2),
IF(AND($P2=0,$AJ20),((($AJ2-$Q2))/$AJ2),
IF(AND($P20,$AG20),((($AG2-$P2))/$AG2),
IF(AND($P2=0,$AG20),((($AG2-$Q2))/$AG2),
IF(AND($P20,$AA20),((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),((($AA2-$Q2))/$AA2),
IF(AND($P20,$X20),((($X2-$P2))/$X2),
IF(AND($P2=0,$X20),((($X2-$Q2))/$X2),0))))))))))))))))


This makes it easier. Again, use P2 when it's greater than zero, use Q2
when P2 equals zero, and return zero when P2 is less than zero. This is
completely separate from the other comparisons.

Then, use the rightmost positive value from the cells BB2, AY2, AS2,
AP2, AJ2, AG2, AA2 and X2. These now follow a single, well-defined
rule, so no more need for OFFSET.

=IF(AND($P2=0,SUMPRODUCT(--(MOD(COLUMN($X2:$BB2),9)={6;0}))),
1-IF($P20,$P2,$Q2)/LOOKUP(3,MATCH(MOD(COLUMN($X2:$BB2),9),{6;0},0)
/($X2:$BB20),$X2:$BB2),0)

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 98
Default More than 16 nested IFs!!!!

Thanks Harlan, works great, sorry about over-complicating it before!
Just one thing... I get #N/A in the cell when all values are 0 but it looks
as though the formula should display a zero if the IF statement is false...
how can I change #NA to 0?

"Harlan Grove" wrote:

Meltad wrote...
....
I need to do the calculation using firstly P or then Q if P=0.
And to use the first value from right to left in the cells BB, AY, AS, AP,
AJ, AG, AA, X to do the rest of the calculation. Here are the corrected IFs

....
[reformatted]
IF(AND($P20,$BB20),
((($BB2-$P2))/BB2),
IF(AND($P2=0,$BB20),
((($BB2-$Q2))/$BB2),
IF(AND($P20,$AY20),
((($AY2-$P2))/$AY2),

....
IF(AND($P2=0,$AY20),((($AY2-$Q2))/$AY2),
IF(AND($P20,$AS20),((($AS2-$P2))/$AS2),
IF(AND($P2=0,$AS20),((($AS2-$Q2))/$AS2),
IF(AND($P20,$AP20),((($AP2-$P2))/$AP2),
IF(AND($P2=0,$AP20),((($AP2-$Q2))/$AP2),
IF(AND($P20,$AJ20),((($AJ2-$P2))/$AJ2),
IF(AND($P2=0,$AJ20),((($AJ2-$Q2))/$AJ2),
IF(AND($P20,$AG20),((($AG2-$P2))/$AG2),
IF(AND($P2=0,$AG20),((($AG2-$Q2))/$AG2),
IF(AND($P20,$AA20),((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),((($AA2-$Q2))/$AA2),
IF(AND($P20,$X20),((($X2-$P2))/$X2),
IF(AND($P2=0,$X20),((($X2-$Q2))/$X2),0))))))))))))))))


This makes it easier. Again, use P2 when it's greater than zero, use Q2
when P2 equals zero, and return zero when P2 is less than zero. This is
completely separate from the other comparisons.

Then, use the rightmost positive value from the cells BB2, AY2, AS2,
AP2, AJ2, AG2, AA2 and X2. These now follow a single, well-defined
rule, so no more need for OFFSET.

=IF(AND($P2=0,SUMPRODUCT(--(MOD(COLUMN($X2:$BB2),9)={6;0}))),
1-IF($P20,$P2,$Q2)/LOOKUP(3,MATCH(MOD(COLUMN($X2:$BB2),9),{6;0},0)
/($X2:$BB20),$X2:$BB2),0)


  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 98
Default More than 16 nested IFs!!!!

I've just copied and pasted the formula in again and now I have #VALUE when
all cells are 0!! This doesn't really matter I just want it for tidy-ness I
guess!

"Harlan Grove" wrote:

Meltad wrote...
....
I need to do the calculation using firstly P or then Q if P=0.
And to use the first value from right to left in the cells BB, AY, AS, AP,
AJ, AG, AA, X to do the rest of the calculation. Here are the corrected IFs

....
[reformatted]
IF(AND($P20,$BB20),
((($BB2-$P2))/BB2),
IF(AND($P2=0,$BB20),
((($BB2-$Q2))/$BB2),
IF(AND($P20,$AY20),
((($AY2-$P2))/$AY2),

....
IF(AND($P2=0,$AY20),((($AY2-$Q2))/$AY2),
IF(AND($P20,$AS20),((($AS2-$P2))/$AS2),
IF(AND($P2=0,$AS20),((($AS2-$Q2))/$AS2),
IF(AND($P20,$AP20),((($AP2-$P2))/$AP2),
IF(AND($P2=0,$AP20),((($AP2-$Q2))/$AP2),
IF(AND($P20,$AJ20),((($AJ2-$P2))/$AJ2),
IF(AND($P2=0,$AJ20),((($AJ2-$Q2))/$AJ2),
IF(AND($P20,$AG20),((($AG2-$P2))/$AG2),
IF(AND($P2=0,$AG20),((($AG2-$Q2))/$AG2),
IF(AND($P20,$AA20),((($AA2-$P2))/$AA2),
IF(AND($P2=0,$AA20),((($AA2-$Q2))/$AA2),
IF(AND($P20,$X20),((($X2-$P2))/$X2),
IF(AND($P2=0,$X20),((($X2-$Q2))/$X2),0))))))))))))))))


This makes it easier. Again, use P2 when it's greater than zero, use Q2
when P2 equals zero, and return zero when P2 is less than zero. This is
completely separate from the other comparisons.

Then, use the rightmost positive value from the cells BB2, AY2, AS2,
AP2, AJ2, AG2, AA2 and X2. These now follow a single, well-defined
rule, so no more need for OFFSET.

=IF(AND($P2=0,SUMPRODUCT(--(MOD(COLUMN($X2:$BB2),9)={6;0}))),
1-IF($P20,$P2,$Q2)/LOOKUP(3,MATCH(MOD(COLUMN($X2:$BB2),9),{6;0},0)
/($X2:$BB20),$X2:$BB2),0)




  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 733
Default More than 16 nested IFs!!!!

Meltad wrote...
Thanks Harlan, works great, sorry about over-complicating it before!
Just one thing... I get #N/A in the cell when all values are 0 but it looks
as though the formula should display a zero if the IF statement is false...
how can I change #NA to 0?

"Harlan Grove" wrote:

....
=IF(AND($P2=0,SUMPRODUCT(--(MOD(COLUMN($X2:$BB2),9)={6;0}))),
1-IF($P20,$P2,$Q2)/LOOKUP(3,MATCH(MOD(COLUMN($X2:$BB2),9),{6;0},0)
/($X2:$BB20),$X2:$BB2),0)


Sorry, I left out a check. Make that

=IF(AND($P2=0,SUMPRODUCT((MOD(COLUMN($X2:$BB2),9) ={6;0})*($X2:$BB20))),
1-IF($P20,$P2,$Q2)/LOOKUP(3,MATCH(MOD(COLUMN($X2:$BB2),9),{6;0},0)
/($X2:$BB20),$X2:$BB2),0)

  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 98
Default More than 16 nested IFs!!!!

Thanks Harlan, perfect!

"Harlan Grove" wrote:

Meltad wrote...
Thanks Harlan, works great, sorry about over-complicating it before!
Just one thing... I get #N/A in the cell when all values are 0 but it looks
as though the formula should display a zero if the IF statement is false...
how can I change #NA to 0?

"Harlan Grove" wrote:

....
=IF(AND($P2=0,SUMPRODUCT(--(MOD(COLUMN($X2:$BB2),9)={6;0}))),
1-IF($P20,$P2,$Q2)/LOOKUP(3,MATCH(MOD(COLUMN($X2:$BB2),9),{6;0},0)
/($X2:$BB20),$X2:$BB2),0)


Sorry, I left out a check. Make that

=IF(AND($P2=0,SUMPRODUCT((MOD(COLUMN($X2:$BB2),9) ={6;0})*($X2:$BB20))),
1-IF($P20,$P2,$Q2)/LOOKUP(3,MATCH(MOD(COLUMN($X2:$BB2),9),{6;0},0)
/($X2:$BB20),$X2:$BB2),0)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested IF statement with VLOOKUP James Hamilton Excel Discussion (Misc queries) 1 August 16th 06 07:46 AM
Nested Subtotals in Excel 2002 KG Excel Discussion (Misc queries) 2 September 10th 05 11:51 AM
Why are my nested sub-totals are displaying incorrectly? chiefdean13 Excel Discussion (Misc queries) 1 July 20th 05 05:45 AM
Nested IF statements John Simons Excel Worksheet Functions 14 February 16th 05 06:17 AM
how can I exceed the nested if fuction limit mgdye Excel Discussion (Misc queries) 5 January 30th 05 02:09 PM


All times are GMT +1. The time now is 06:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"