Quartz | Level 8

## How to use IFN function with multiple conditions?

Hi,

I'm trying to make the following code to be shorter:

``````	If Period = 40 Then Do;
If Years > 20 and Years < 30 Then
Effect_on_Guarantee = 1;
Else Effect_on_Guarantee = Lapse_Multipliers;
End;
Else Effect_on_Guarantee = Lapse_Multipliers;``````

To achieve this I'm trying to use IFN function like this:

``IFN(a.Period = 40, IFN((a.Period  > 20 and a.Period < 30),1, Lapse_Multipliers),Lapse_Multipliers) As Effect_on_Guarantee``

In This way IFN doesn't return any error or warning but doesn't the work as along version of code does.

Where is a mistake?

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: How to use IFN function with multiple conditions?

@IgorR wrote:

In This way IFN doesn't return any error or warning but doesn't the work as along version of code does.

Where is a mistake?

You have NOT told us what is wrong. Saying it doesn't work gives us no useful information. What do you see that is wrong?

Why do you switch from a variable named YEAR to a variable named PERIOD? Could that be the problem?

--
Paige Miller
3 REPLIES 3
Super User

## Re: How to use IFN function with multiple conditions?

Why would you want to convert readable code into a function call?

If it is so you add it to an SQL statement then use CASE clause.

``````case when (Period = 40) then
case when (Years > 20 and Years < 30) then 1 else Lapse_Multipliers end
else Lapse_Multipliers
end``````

If you want to reduce the LOGIC of the test then do:

``````case when ((Period = 40) and (Years > 20 and Years < 30)) then 1
else Lapse_Multipliers
end``````

Diamond | Level 26

## Re: How to use IFN function with multiple conditions?

@IgorR wrote:

In This way IFN doesn't return any error or warning but doesn't the work as along version of code does.

Where is a mistake?

You have NOT told us what is wrong. Saying it doesn't work gives us no useful information. What do you see that is wrong?

Why do you switch from a variable named YEAR to a variable named PERIOD? Could that be the problem?

--
Paige Miller
Quartz | Level 8

## Re: How to use IFN function with multiple conditions?

Oh, Thank you!
What a silly mistake.
The problem indeed in switching Years to Period.
Now I fixed it and it works.
Discussion stats
• 3 replies
• 860 views
• 2 likes
• 3 in conversation