Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Nested If Statements

Hello,

I am looking to create a field based on two other fields using nested if statements. 

   

LTV  Pct20 years of less20.01 years or more
>95%613
90.01-95%512
85.01-90%410
85% or less36

The first field is LTV Pct and the second field is Loan Term Actual Mths (i.e. 20 years or less / 20.01 years or more).

Based on these two fields using the table above, I want to assign values to a new field titled "Years".

EXAMPLE:

If [LTV Pct] >95% AND [Loan Term Actual Mths] >20.01, [Years] = 13.

Please let me know if you have any questions.  Thank you in advance!

6 Replies
sunny_talwar

Not sure how the data is laid out but a nested if statement can work

If([LTV Pct] <= 0.85,

                              If([Loan Term Actual Mths] > 20.01, 6, 3),

If([LTV Pct] <= 0.90,

                              If([Loan Term Actual Mths] > 20.01, 10, 4),

If([LTV Pct] <= 0.95,

                              If([Loan Term Actual Mths] > 20.01, 12, 5),

If([LTV Pct] > 0.95,

                              If([Loan Term Actual Mths] > 20.01, 13, 6))))) as Years

Anonymous
Not applicable
Author

Hi Sunny, thank you so much!

I agree this logic would work, however, I am getting an error message that 'Loan Term Actual Mths' is not being recognized in the if statement lines. 

Any ideas why?

sunny_talwar

I have assumed that you have a field named Loan Team Actual Mths in your database (or is getting created somewhere before the if statement. If the field isn't there, you will see an error message. Can you share your script?

Anonymous
Not applicable
Author

I actually created a field [Loan Term Actual Years], which converts months to years.  Here is my script below:

     [LTV Pct],

     [Base Loan Amt],

     [Current Loan Amt],

     [Loan Term Actual Mths],

     [Loan Term Actual Mths]/12 as [Loan Term Actual Years],

     If([LTV Pct] <= 0.85,If([Loan Term Actual Years] > 20.01, 6, 3),

     If([LTV Pct] <= 0.90,If([Loan Term Actual Years] > 20.01, 10, 4),

     If([LTV Pct] <= 0.95,If([Loan Term Actual Years] > 20.01, 12, 5),

     If([LTV Pct] > 0.95,If([Loan Term Actual Years] > 20.01, 13, 6))))) as Years,

sunny_talwar

Try this:

LOAD *,

     If([LTV Pct] <= 0.85,If([Loan Term Actual Years] > 20.01, 6, 3),

     If([LTV Pct] <= 0.90,If([Loan Term Actual Years] > 20.01, 10, 4),

     If([LTV Pct] <= 0.95,If([Loan Term Actual Years] > 20.01, 12, 5),

     If([LTV Pct] > 0.95,If([Loan Term Actual Years] > 20.01, 13, 6))))) as Years;

LOAD [LTV Pct],

     [Base Loan Amt],

     [Current Loan Amt],

     [Loan Term Actual Mths],

     [Loan Term Actual Mths]/12 as [Loan Term Actual Years],

The above set up is called 'Preceding Load'. The Field Loan Term Actual Years is not available in the preceding load and can now be referred to create Years.

Anonymous
Not applicable
Author

This appears to be working.  Thank you very much!