Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

IF statement, compare a variable against a field value

Hi All,

I am trying to get an IF statement working where a variable is compared against a field value. My code is:

SET MyLocalVariable = 'test';

MyTable:
LOAD Field1,
Field2,
Field3
FROM
MyTable.qvd] (qvd);

IF MyLocalVariable <> Field1 THEN
// Some more code
//...
Exit script;
END IF


Unfortunate this isn't working. In the IF statement Field1 seems to be NULL when checking in the debugger. I am sure that Field1 of the table is filled with a string value. No Unqualify is set.

How can I make this statement work, e.g. compare a variable against a field value?

Thanks,
Korrelzeep

1 Solution

Accepted Solutions
Not applicable
Author

You must use peek or fieldvalue function to get the value from a table and match it against a variable. if the table has more than one value, then you much use a for loop if you want to compare all the values.

View solution in original post

4 Replies
Not applicable
Author

Try something like this


SET MyLocalVariable = 'test';


MyTable:
LOAD Field1,
If(Field1=$(MyLocalVariable) , 1 , 0 ) as Flag
Field2,
Field3
FROM
MyTable.qvd] (qvd);


where you create a new field Flag = 1 if Field1='test'

regards

jjj

Not applicable
Author

You must use peek or fieldvalue function to get the value from a table and match it against a variable. if the table has more than one value, then you much use a for loop if you want to compare all the values.

Not applicable
Author


Hi syed.maqsood,

Thank you, that did the trick.

Regards,
Korrelzeep

Not applicable
Author


Hi Jean-Jacques,

Thank you for your suggestion. Unfortunate I am not sure I can use this at this moment because is it giving me a new field which I cannot test either. I think your solution provides a new field which can be shown on a sheet. However I really need to test the condition in the script because the script must be ended when the condition is true.

Regards,
Korrelzeep