IIF statements with And

slimjen1

Registered User.
Local time
Today, 11:18
Joined
Jun 13, 2006
Messages
562
All,

I am trying to make an IIF statement with three possible outcomes and not working:

Code:
IIf([status]="Active" and [Type]= “Cost”,[rate1]-[rate2]+[ rate4],IIf([status]="InActive",[ rate1]+[rate3],[ rate2]+[rate3])) AS newRate

It tells me i'm missing parathesis or wrong argument. I keep changing to make it correct but still getting errors. Can someone look at it and make suggestions please. Thanks
 
What errors are you getting?

I see that you have spaces before some field names that are probably incorrect:

[ rate2] and [rate2]

Do you actually have 2 different fields?
 
the space is a typo. I'm getting wrong number of arguments or missing parenthesis
 
Maybe it is a typo also, but your quotes is of a wrong type!

Code:
IIf([status]="Active" and [Type]= [B][COLOR=Red]“[/COLOR][/B]Cost[B][COLOR=Red]”[/COLOR][/B],[rate1]-[rate2]+[ rate4],IIf([status]="InActive",[ rate1]+[rate3],[ rate2]+[rate3])) AS newRate
 
I agree with JHB
Also it sometimes helps to put each bit in brackets to clarify the process

Code:
IIf([status]="Active" and [Type]= "Cost",([rate1]-[rate2]+[rate4]),(IIf([status]="InActive",[rate1]+[rate3],[rate2]+[rate3]))) AS newRate
 
Ok. I put extra parenthesis around and it worked. But then I realized I forgot the else in the first part and now it tells me the "," is incorrect.

Code:
IIf([status]= "Active" and [Type]= "Cost",([rate1]-[rate2]+[rate4[B]],[rate1][/B]),(IIf([status]="InActive",[rate1]+[rate3],[rate2]+[rate3])) AS newRate
 
You didn't forget it, the else IS the second iif...
 

Users who are viewing this thread

Back
Top Bottom