Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
So, in a LOAD script you can do IF-AND and IF-OR like:
IF(A=1 AND B=1, 1, 0) as _flagTest
IF(B=1 OR C=1, 1, 0) as _flagTest
For cases where we need to use both logical operators, as far as I know you would have to get nesty, so for example like:
IF(A=1 and B=1, 1,
IF(C=1, 1, 0)) as _flagTest
Question: is there an unnested way? Like:
IF(A=1 and B=1 or C=1, 1, 0) as _flagTest
Can QlikView evaluate this? If so, which operator takes precedence? I mean, like:
A |
B |
C |
_flagTest |
1 |
1 |
<>1 |
1 |
1 |
<>1 |
1 |
1 |
<>1 |
1 |
1 |
0 |
1 |
<>1 |
<>1 |
0 |
<>1 |
1 |
<>1 |
0 |
<>1 |
<>1 |
1 |
0 |
…or like:
A |
B |
C |
_flagTest |
1 |
1 |
<>1 |
1 |
1 |
<>1 |
1 |
1 |
<>1 |
1 |
1 |
1 |
1 |
<>1 |
<>1 |
0 |
<>1 |
1 |
<>1 |
0 |
<>1 |
<>1 |
1 |
1 |
?
Thanks,
Robin
There shouldn't be a problem with this. Ideally, you should parenthesize to tell Qlik what the parsing order, for example:
if((1 = 2 AND 3 = 4) OR 5 =5,'Yes','No') = Yes
if(1 = 2 AND (3 = 4 OR 5 =5),'Yes','No') = No
Note that without parenthesizing:
if(1 = 2 AND 3 = 4 OR 5 =5,'Yes','No') = Yes
There shouldn't be a problem with this. Ideally, you should parenthesize to tell Qlik what the parsing order, for example:
if((1 = 2 AND 3 = 4) OR 5 =5,'Yes','No') = Yes
if(1 = 2 AND (3 = 4 OR 5 =5),'Yes','No') = No
Note that without parenthesizing:
if(1 = 2 AND 3 = 4 OR 5 =5,'Yes','No') = Yes
Wizard of Or, thanks for the input,
Splendid piece of info that parenthesizing work in that way. Out of curiosity, your parenthesis-less last example indicates that parsing order is just based on execution left to right? Nothing like difference in force between AND/OR?
Thanks,
Robin
I've never given it too much thought, to be honest. Even if I knew and remembered what happened in this scenario, I find it difficult to read and would much rather have the logic explicitly stated via parenthesizing. That said, you should be able to test this fairly easily if you want to.