Multiple if statements

  • Thread starter Thread starter Big Tony
  • Start date Start date
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?
 
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.
 
In this case, Choose() might be a better choice:
=Choose(x12, "WHITE","RED","Blue","GREEN")
Check Help for the syntax.
 
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
 
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
.
 
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.
.
 
Back
Top