Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
MAlex1
Contributor
Contributor

An issue with AND operator in an expression

Hello everybody,

 

I am struggling with some issues in tMap expression. There is the table with those fields:

 

ANRED (the title of person) with those values:

MR 1
MISS 2
MRS 3
MS 4
DR null

 

GESCH (gender key) with those values:

Female 2
Male 1

 

For the case when ANRED value is null I need to use this rule for output:

 

IF ANRED = null AND GESCH = 2 then output_value = 4 ELSE output_value = 1.

 

This is my expression:

(Basic_G2_Structure2.ANRED==null)&&(Basic_G2_Structure2.GESCH!="2")?"1":"4"

 

0683p000009M8O1.png

 

Unfortunately, the output from the expression is always '1' for all ANRED values although the values are correct on input.

 

0683p000009M97I.png

 

I guess I have something wrong in the expression but I do not know what.

 

Could you someone advise me, please?

 

Thank you.

 

/Martin

Labels (2)
17 Replies
MAlex1
Contributor
Contributor
Author

Hi Manohar,

 

the result is again better than previously. But still not good.

 

Here is current input  (Basic_G2_Structure):

 

|=----+-----+-----+-----+-----+-----+-----+

|RECTY|CLIID|CNAME|RUFNM|KNZNM|ANRED|GESCH|

|=----+-----+-----+-----+-----+-----+-----+

|P0002|42730|null |null |null |1    |1    |

|P0002|42737|null |null |null |1    |1    |

|P0002|42762|null |null |null |null |1    |

|P0002|42768|null |null |null |3    |2    |

|P0002|42774|null |null |null |3    |2    |

|P0002|42782|null |null |null |3    |2    |

|P0002|42784|null |null |null |3    |2    |

|P0002|42789|null |null |null |4    |2    |

|P0002|42793|null |null |null |1    |1    |

|=----+-----+-----+-----+-----+-----+-----+

 

here is the expression:

 

(Basic_G2_Structure2.ANRED==null || ("").equals(Basic_G2_Structure2.ANRED)|| ("1").equals(Basic_G2_Structure2.ANRED))&& ("1").equals(Basic_G2_Structure2.GESCH)?"1" :"4"

 

and here is the output after processing:

 

|=----+-----+-----+-----+-----+-----+-----+

|RECTY|CLIID|CNAME|RUFNM|KNZNM|ANRED|GESCH|

|=----+-----+-----+-----+-----+-----+-----+

|P0002|42730|null |null |null |1    |1    |

|P0002|42737|null |null |null |1    |1    |

|P0002|42762|null |null |null |1    |1    |

|P0002|42768|null |null |null |4    |2    |

|P0002|42774|null |null |null |4    |2    |

|P0002|42782|null |null |null |4    |2    |

|P0002|42784|null |null |null |4    |2    |

|P0002|42789|null |null |null |4    |2    |

|P0002|42793|null |null |null |1    |1    |

|=----+-----+-----+-----+-----+-----+-----+

 

In the case CLIID  42762 the expression works according to expectation:

 

|=----+-----+-----+-----+-----+-----+-----+

|RECTY|CLIID|CNAME|RUFNM|KNZNM|ANRED|GESCH|

|=----+-----+-----+-----+-----+-----+-----+

|P0002|42762|null |null |null |1    |1    |

|=----+-----+-----+-----+-----+-----+-----+

 

But for all cases where GESCH value before processing = 2 the ANRED value was changed from original to new value '4' after processing via the expression:

 

|=----+-----+-----+-----+-----+-----+-----+

|RECTY|CLIID|CNAME|RUFNM|KNZNM|ANRED|GESCH|

|=----+-----+-----+-----+-----+-----+-----+

|P0002|42730|null |null |null |1    |1    |

|P0002|42737|null |null |null |1    |1    |

|P0002|42762|null |null |null |1    |1    |

|P0002|42768|null |null |null |4    |2    |

|P0002|42774|null |null |null |4    |2    |

|P0002|42782|null |null |null |4    |2    |

|P0002|42784|null |null |null |4    |2    |

|P0002|42789|null |null |null |4    |2    |

|P0002|42793|null |null |null |1    |1    |

|=----+-----+-----+-----+-----+-----+-----+

 

So, there is still something in the expression that causes change ANRED value despite the original ANRED value = null.

 

There is condition with logical AND:

 

IF ANRED = null AND IF GESCH = "1" THEN ANRED = "1" ELSE ANRED = "4"

 

so, both conditions have to match at the same time within the evaluation.

 

Thanks a lot for your support again.

 

/Martin

manodwhb
Champion II
Champion II

@MAlex , can you try with below expression.

(Basic_G2_Structure2.ANRED==null && ("1").equals(Basic_G2_Structure2.GESCH))?"1" :"4"

Ganshyam
Creator II
Creator II

Hello @MAlex ,

 

You require below results?


0683p000009MA5r.png

Regards

 

MAlex1
Contributor
Contributor
Author

Hi Manohar,

 

with this expression:

 

(Basic_G2_Structure2.ANRED==null && ("1").equals(Basic_G2_Structure2.GESCH))?"1" :"4"

 

we have returned back to begin:

 

input Final_G2_Structure

ID

ANRED

GESCH

100

1

1

101

4

2

103

1

1

104

2

2

105

4

1

 

Unfortunately, the output is the following:

 

output Final_G2_Structure

ID

ANRED

GESCH

100

4

1

101

4

2

103

4

1

104

4

2

105

4

1

 

However, thank you for your help.

 

/Martin

MAlex1
Contributor
Contributor
Author

Hello  Ganshyam,

 

thank you for your interest. Really, it looks like the output from the expression which I am looking for …

 

/Martin

MAlex1
Contributor
Contributor
Author

Hi Ganshyam,

 

any idea how to get the output on your screenshot via an expression?

 

Thank you.

 

/Martin

Ganshyam
Creator II
Creator II

Hello @MAlex 

I tried below condition to get your expected result.Try it out and validate against your input data.

 

(row1.ANRED.equals("null")|| row1.ANRED.equals("1"))&& row1.GESCH.equals("1")?"1" :
row1.ANRED.equals("null")&& !row1.GESCH.equals("1")?"4":row1.ANRED

 

Regards

 

MAlex1
Contributor
Contributor
Author

Hello Ganshyam,

thanks a lot! Your solution is OK, just small adjustment was necessary:

(row1.ANRED==null || row1.ANRED.equals("1"))&& row1.GESCH.equals("1")?"1": row1.ANRED==null&& !row1.GESCH.equals("1")?"4":row1.ANRED

Thank you again.

/Martin