Using "AND" in an IIF function statement

A

AMFLMSC

This is what I am trying to do:

I have two conditions that I want the if statement to look at.
If my CF_Premium is greater than 0 and my FLS_Premium is less than 0, add the
two values.

This is what I tried first and I get an error message:
Premium_Variance:IIF(and([CF_Premium]>0,[FLS_Premium]<0),[CF_Premium]+
[FLS_Premium],IIF(and([CF_Premium]<0,[FLS_Premium]>0),[CF_Premium]+
[FLS_Premium],0))

Then I tried this:

Premium_Variance:IIF([CF_Premium]>0 and [FLS_Premium]<0,[CF_Premium]+
[FLS_Premium],IIF([CF_Premium]<0 and [FLS_Premium]>0,[CF_Premium]+
[FLS_Premium],0))
 
K

KARL DEWEY

If my CF_Premium is greater than 0 and my FLS_Premium is less than 0, add
the two values.

IIF([CF_Premium]>0 and [FLS_Premium]<0,[CF_Premium]+[FLS_Premium],0)
 
J

Josh D

Your first solution is an Ecel notation for AND -- and(varA,VarB,..VarN) and
does not work in VB. However, your second solution is correct only it adds
the 2 numbers together regardless if:
CF_Premium < 0 AND FLS_Premium > 0 *** OR ***
CF_Premium > 0 AND FLS_Premium < 0

Josh D
 

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

Top