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

2 conditions met in if statement

Hi,

Two conditions met from same field.

 

Test

1

2

3

4

If(Test = 1 and Test = 3, 1,0) as xzy

 

Why is this not working?

I need both, not 1 or 1 or the other I need both.

 

Thanks

 

 

9 Replies
JGMDataAnalysis
Creator III
Creator III

Your expression does not make sense, the condition will never be met because a value cannot be equal to 1 and 3 simultaneously.

Try the following...

If(Test = 1 OR Test = 3, 1, 0) AS xzy

 

D19PAL
Creator II
Creator II
Author

Or means one or the other doesn't it?

I need the condition to be test 1 and 3 both selected, if both selected then a yes or no.

Thanks

 

D19PAL
Creator II
Creator II
Author

That's the whole thing, how can I do it to achieve my goal.

I'm trying it via generic table, create a key and join it via a excel spreadsheet lookup table.

Must be an easier way

 

 

JGMDataAnalysis
Creator III
Creator III

If the definition of the flag depends on the user's selection, you cannot solve it in script. In what context are you going to use it?

 

If(Concat(Distinct [Test], ', ') = '1, 3', 1, 0)

 

 

D19PAL
Creator II
Creator II
Author

It's not selected by a user in the frontend, it's in the data for reporting purposes.

marcus_sommer

You could apply the same string-aggregation in the script - but you will need an extra group by load for it because an aggregation returns only the expected values if it matched the right context/dimensionality and then you map/join the result back to the target-table or you may keep the table as dimension-table within  the datamodel.

- Marcus

D19PAL
Creator II
Creator II
Author

Thanks

Do you have the syntax for that or a link to how to do it?

There's so much info on multiple conditions from multiple fields but nothing on multiple conditions on one particular field.

 

 

 

 

marcus_sommer

You may apply something like this:

m: mapping load key, concat(test, '+') from source group by key;

final:
load *, if(x = 'condition', 1, 0) as Check;
load *, applymap('m', key, null()) as x from source;

- Marcus

D19PAL
Creator II
Creator II
Author

I'll give it a shot.

 

Thanks