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

creating if statement in loop

Hi colleagues.

I'm working now with creating variable which will be used as IF statement in next load.

What is the idea?

I have simple table like:

   

ID_CondConditionCategory
1Name=AFirst
2Name=BSecond
3Name=CThird

what i need - create if statement with checking all ID_Cond values and corresponded Condition to set necessary Category, for example:

IF(ID=1 and Name='A', 'First',

     IF(ID=2 and Name='B', 'Second',


...                    ,   'non'))


I started to create this variable in loop, but stopped with appending to if statement in the loop (see example in the attachment).

Any  idea how to correctly create this statement?


In result my variable should have this value:

'IF([ID_Cond]='1' and ([Name]='A'), 'First',

    IF([ID_Cond]='2' and ([Name]='B'), 'Second',

         IF([ID_Cond]='3' and ([Name]='C'), 'Third', 'Non') as NewField;'





Thanks/

1 Reply
Anonymous
Not applicable
Author

Hi

what you can do is reload your table.

Table2:

load *,

IF([ID_Cond]='1' and ([Name]='A'), 'First',

    IF([ID_Cond]='2' and ([Name]='B'), 'Second',

         IF([ID_Cond]='3' and ([Name]='C'), 'Third', 'Non'))) as NewField

resident Table1;

drop table  Table1; rename table Table2 to Table;



then you'll have a Table with the fields  ID_Cond, Name and NewField.



i hope I helped you.


RS