View Full Version : Expressions


pacotx
07-29-2006, 10:30 AM
Help me what is wrong with this expression:eek: :

=IIF( [eBay Method] ="Auction",
IIF( [Start up Price] <=.99,.2,
IIF( [Start up Price] < = 9.99,.35,
IIF( [Start up Price] < =24.99,.6,
IIF( [Start up Price] < =49.99,1.2,
IIF( [Start up Price] < =199.99,2.4,
IIF( [Start up Price] < =499.99,3.6,
IIF( [Start up Price] >499.99,4.8," "
))))))),
IIF( [eBay Method] ="Buy it Now",
IIF( [Start up Price] <=9.99,.05,
IIF( [Start up Price] <=24.99,.1,
IIF( [Start up Price] <=49.99,.2,
IIF( [Start up Price] <=49.99,.25," "
))))))

neileg
07-31-2006, 02:35 AM
Too many nested IIFs perhaps?

Try a Case() statement instead.

raskew
07-31-2006, 02:59 AM
Hi -

The Switch() function also works well and reduces the amount of code. Here's an example from the debug (immediate) window:
startupprice = 123.49
x = startupprice
y = switch(x<=0.99,0.2, x<=9.99,0.35, x<=24.99, 0.6,x<=49.99,1.2,x<=199.99,2.4,x<=499.99,3.6,true,4.8)
? y
2.4


HTH - Bob

pacotx
07-31-2006, 08:58 AM
Is there anything wrong with the syntax?

raskew
07-31-2006, 05:15 PM
If it's not working for you then obviously there is something wrong with the syntax. As pointed out, too many nested Iif's create an unreadable monster. Suggest you look at Case() statements or the Switch() function as a couple of ways of creating readable, editable code.

Bob