Multiple if statements

B

Big Tony

If I want to make an IIf statement that hinges more than
two situations (say three or four possible outcomes), is
it possible to embed IIF statements inside each other,
like you can in excel?

Ex: =IIF(x12=4,"GREEN",IIF(x12=3,"Blue",IIF
(x12=2,"RED","WHITE")))

In addition, is there perhaps an alternative, more
efficient way to do this?
 
F

fredg

If I want to make an IIf statement that hinges more than
two situations (say three or four possible outcomes), is
it possible to embed IIF statements inside each other,
like you can in excel?

Ex: =IIF(x12=4,"GREEN",IIF(x12=3,"Blue",IIF
(x12=2,"RED","WHITE")))

In addition, is there perhaps an alternative, more
efficient way to do this?

In a query you do NOT use the initial = sign.
If the criteria values are number datatypes:

Ex:IIf([FieldName]=4,"Green",IIf([FieldName]=
3,"Blue",IIf([Fieldname]=2,"White","No value")))

If the criteria values are text datatype surround them with double
quotes also:
Ex:IIf([FieldName]="4","White", etc.
 
D

Duane Hookom

In this case, Choose() might be a better choice:
=Choose(x12, "WHITE","RED","Blue","GREEN")
Check Help for the syntax.
 
G

Gerald Stanley

Nested IIf statements are perfectly fine. An alternative
is the SWITCH function that works with pairs of parameters;
the first being the condition and the second the action if
the condition is true. In your example, this would be

=Switch(x12>4,"WHITE",x12=4,"GREEN",x12=3,"Blue",x12=2,"RED",x12<2,"WHITE")

Hope This Helps
Gerald Stanley MCSD
 
G

Guest

thank you, very helpful
-----Original Message-----
Nested IIf statements are perfectly fine. An alternative
is the SWITCH function that works with pairs of parameters;
the first being the condition and the second the action if
the condition is true. In your example, this would be

=Switch (x12>4,"WHITE",x12=4,"GREEN",x12=3,"Blue",x12=2,"RED",x12<
2,"WHITE")

Hope This Helps
Gerald Stanley MCSD
.
 
G

Guest

thank you, very helpful
-----Original Message-----
If I want to make an IIf statement that hinges more than
two situations (say three or four possible outcomes), is
it possible to embed IIF statements inside each other,
like you can in excel?

Ex: =IIF(x12=4,"GREEN",IIF(x12=3,"Blue",IIF
(x12=2,"RED","WHITE")))

In addition, is there perhaps an alternative, more
efficient way to do this?

In a query you do NOT use the initial = sign.
If the criteria values are number datatypes:

Ex:IIf([FieldName]=4,"Green",IIf([FieldName]=
3,"Blue",IIf([Fieldname]=2,"White","No value")))

If the criteria values are text datatype surround them with double
quotes also:
Ex:IIf([FieldName]="4","White", etc.
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top