Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Nested If statements

I'm wondering how Qlikview handles Nested If Statments. For example, is there a difference between the code below

Example 1:

if( x > y, 'Yes',

     if( J = U, 'Missing',

          if(R < H, 'Hung Up', 'Successful'))) as [Call Outcome]

Example 2:

if(x>y, 'Yes') as [Call Outcome]

if(J=U, 'Missing') as [Call Outcome]

if( R < H, 'Hung Up', 'Successful') as [Call Outcome]

7 Replies
Anonymous
Not applicable
Author

your Example2 won't run

you can only define one fieldname

otherwise you get an error message

you Need to use a nested if like example 1

kuczynska
Creator III
Creator III

Hi Seth,

I don't think code from Example 2 would work in your load script as I would expect QV to return an error - something like "columns in your tables must have unique names" --> let's not forget that QV builds the association between the tables based on field name (and it is case sensitive), so it will not allow you to create 3 [Call Outcome] fields.

Example 1 would work - of course considering that that's the logic you need in your script.

Hope that helps, good luck!


maxgro
MVP
MVP

I think you get a syntax errore for the second one

Not applicable
Author

Ok, so example 2 won't work. Disregarding how qlikview would handle this, is the logic at least the same. In other words, in qlikview you must nest the if statements, but really all the logic is, is a bunch of if statements together with no difference in priority. Does that make sense?

stigchel
Partner - Master
Partner - Master

No difference in priority? Do you mean you would like all if statements to produce a value?

If so you might want to take a look at the crosstable load, see help and/or

The Crosstable Load

stigchel
Partner - Master
Partner - Master

A example for your situation would be something like this

Database:

Load ID,x,y,J,U,R,H

From...

CrossTable(Metric,Data,1) load

ID,

if(x>y, 'Yes') as [Call Outcome],

if(J=U, 'Missing') as [Call Outcome],

if( R < H, 'Hung Up', 'Successful') as [Call Outcome]

resident Database;

rupamjyotidas
Specialist
Specialist

There won't be any difference in nested if else, you can use the same logic as you would do in any programming language. Your second one will give error for field names as the Qv works on field name.