Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Nested if Condition in Script

Hi all,

I am new to qlikview. I used nested if conditions in my script. But some of the conditions doesnt work. (Test1 and Test2, mentioned in the script)

Sample:

LOAD Product,

if((Product='Two Wheelers' or Product='Three Wheelers') and Level='Level1','Test3',

  if(Product='Two Wheelers','Test1',

  if(Product='Three Wheelers','Test2'))) as New_Skill,

  Level,

  Value

FROM

(ooxml, embedded labels, table is Sheet2);

I know the first condition satisfies , so it not performing the other conditions. But i need Test1 and Test2 in the New_Skill Field.

Please find the attachment and help me sort out this issue.

Regards,

Siva

13 Replies
stigchel
Partner - Master
Partner - Master

If I understand you correctly and you need more values per row for the New_Skill field you can use a crosstable load, something like (Also see attached)

Sample:

LOAD Product,

  Level,

  Value

FROM

[Sample.xlsx]

(ooxml, embedded labels, table is Sheet2);

CrossTable (New_Skill,Product,1) load

RowNo() As Id,

if((Product='Two Wheelers' or Product='Three Wheelers') and Level='Level1',Product) as Test3,

  if(Product='Two Wheelers',Product) as Test1,

  if(Product='Three Wheelers',Product) as Test2

resident Sample;

Qrishna
Master
Master

IS this what you are expecting?

Capture1.PNG

Please see attached.

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Based on your condition and your data, the second and the third condition will never get processed. In order to see "Test1" and "Test2", you should have some Two Wheelers and Three Wheelers with Level other than Level1.

Not applicable
Author

Hi,

Sample:

LOAD Product,

  if(Product='Two Wheelers' and Level='Level1','Test3',

  if(Product='Three Wheelers' and Level='Level1','Test3',

  if(Product='Two Wheelers','Test1',

  if(Product='Three Wheelers','Test2')))) as New_Skill,

  Level,

  Value

FROM

Sample.xlsx

(ooxml, embedded labels, table is Sheet2);

Try the above code.

Please see attached qvw also. To check I have added two rows in your excel.

pratap6699
Creator
Creator

product_tbl:

LOAD Product,

  if(Product='Two Wheelers' and Level='Level1','Test3',

  if(Product='Three Wheelers' and Level='Level1','Test3',

  if(Product='Two Wheelers','Test1',

  if(Product='Three Wheelers','Test2')))) as New_Skill,

  Level,

  Value

FROM

Sample.xlsx

your expecting output is like this??.

    

ProductNew_SkillLevelValue
Four Wjeelers Level2300
JCB Level3400
Three WheelersTest2Level3250
Three WheelersTest3Level1200
Two WheelersTest1Level2150
Two WheelersTest3Level1100
jonathandienst
Partner - Champion III
Partner - Champion III

if(Product='Two Wheelers' and Level='Level1','Test3',

if(Product='Three Wheelers' and Level='Level1','Test3',

if(Product='Two Wheelers','Test1',

if(Product='Three Wheelers','Test2')))) as New_Skill,  

Logically identical to the original post...

See Oleg Troyansky's post

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Thanks for your reply. Actually the Linking field here is product. But in my case both tables are linked by two fields.

For Example : ProductID&'-'&CategoryID.

I am not able to bring this key field in the crosstable . I hope you can understand my response.

Regards,

Siva

jonathandienst
Partner - Champion III
Partner - Champion III

There's nothing wrong with your script. You just have no data in your source sample that satisfies the conditions for Test2 and Test3.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

yes i know there is no data fro Test 2 and Test 3. Actually the Cross table concept is correct. It works. But the problem is , not able to bring the key fields in the cross table.

Regards,

Siva