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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

if condition in load script

I have two Fields

FieldA has two values A and B

FieldB has Y and N

FieldC has numbers.

I am trying to fetch values from FieldC based on condition on FieldA and FieldB in the Load Script as below:

if([FieldA]='A' and [FieldB]='Y', [FieldC])

If FieldA has A and FieldB has Y as values, then the column FieldC should get all the values corresponding to the condition. But I get this error saying Invalid Expression. How to achieve this in Load Script level.

22 Replies
swuehl
MVP
MVP

if(Field1='A', and FieldB='Y', then Field3) as [DefinedValue]


if(Field1='A' and FieldB='Y' or FieldB = 'N', Field3) as [DefinedValue]

sunny_talwar

Yes, I would think so. Is it not working?

Anonymous
Not applicable
Author

I don't see any error. But I see that the conditions are not being evaluated. The resultant field is showing incorrect values.

sunny_talwar

Can you explain your condition in plain simple English?

vikramv
Creator III
Creator III

I guess , you need to use DUal function like this.

Dual & Exists – Useful Functions

Thanks.

Vikram

Anonymous
Not applicable
Author

I need to check for a value in Field1, check for two values in Field2 ( Like A or B) and then depending on the conditions, I should display the value present in Field3 as DefineValue columm.

I hope you got it, Sunny

vikramv
Creator III
Creator III

Check this from the help that may help you

lookup(fieldname, matchfieldname, matchfieldvalue [, tablename])

Returns the value of fieldname corresponding to the first occurrence of the valuematchfieldvalue in the field matchfieldname.

Fieldname, matchfieldname and tablename must be given as strings (e.g. quoted literals).

The search order is load order unless the table is the result of complex operations such as joins, in which case the order is not well defined.

Both fieldname and matchfieldname must be fields in the same table, specified bytablename. If tablename is omitted the current table is assumed.

If no match is found, null is returned.

Example:

lookup('Price', 'ProductID', InvoicedProd, 'pricelist')

sunny_talwar

I would think this to work:

If(Field1='A' and Match(FieldB, 'Y', 'N'), Field3) as [DefinedValue]

Would you be able to share a sample where this isn't working?

Anonymous
Not applicable
Author

Sorry Vikram, I need to check for two values in Field2. It's not just one value in Field1. This thing doesn't work in this case.

Conditions example:

if Field1 has X

if Field2 has Y or N,

then Field3 as DefinedValue.

In this case, you maybe able to do it for one value, but I need to check for two values in the Field2

Anonymous
Not applicable
Author

The sample data i can provide is the same examples I have been using, Sunny. My original data is too complicated and also, privacy issues. So I will try it from my end and will get back if I can't figure it out. Thanks again