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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

multiple if conditions in tmap

Hi All,

I  have a requirement to transform the data from source to target. below is the requirement.

In T_USER_DIM the column will have 3 possible values: value null when st_user.external_employee=1. value ‘y' when st_user.external_employee=0 and the st_user.external_id is found in st_us_persons. value 'n’ when st_user.external_employee=0 and the st_user.external_id is not found in st_us_persons.

i have written expression like this in tmap, but it is not working.

(ST_USER.external_employee=="1")?"Null" : ( ( ST_USER.external_employee == "0")?"Y":"N"

 

Labels (3)
11 Replies
PLITDT
Contributor
Contributor

Hi,

 

To check if st_user.external_id exists in st_us_person you will need to join on that table. You can then check if the external_id is null or not.

If the data type of the column st_user.external_employee is an integer, there is no need to surround 1 or 0 with quotes in the conditional statements. If it is a String, you have to use st_user.external_employee.equals("1") instead.

Try this and see if it works:

st_user.external_employee == 1 ? null:
st_user.external_employee == 0 && st_us_persons.external_id != null ? "Y":
st_user.external_employee == 0 && st_us_persons.external_id == null ? "N" : "X"
Anonymous
Not applicable
Author

Hi @plID,

 

Thank you for your response,i have a join between these 2 tables and the data type of the column st_user.external_employee  is Varchar. i have one more question, do we need to enclose the statements in braces or simply adding the condition in the expression editor will work.0683p000009M9Gj.jpg

karthikj18
Contributor III
Contributor III

Both works. Make sure that you are using correct braces in multiple if conditions.

Anonymous
Not applicable
Author

@karthikj18 ,

 

expression is throwing error, below is the screenshot.

 

0683p000009M9HS.jpg

Anonymous
Not applicable
Author

my source column is string datatype and my target is character, how to fix this 

PLITDT
Contributor
Contributor

Hi,

 

To check whether one String is equal to another you cannot use the operator "==". Instead you should use st_user.external_employee.equals("1"). To convert a String into a char you can use the mystring.charAt(0) method. Make sure to check if the variable is null or not first as you cannot call this method on a null value.

 

Taken together, try to create a variable in the tMap to do the multiple conditions and then convert to char in the expression field of the output mapping (see below).0683p000009M9HE.png

Anonymous
Not applicable
Author

Hi @plID ,

Thank you for your response, i have made changes you mentioned, but still i'm getting this error0683p000009M9J4.jpg0683p000009M9J9.jpganges like you 

manodwhb
Champion II
Champion II

@keshav1991 , can you check the check box for key for us_person filed in output section of tMap? 

 

 

Anonymous
Not applicable
Author

Hi @manodwhb ,

 

I have done that as well but no luck.

0683p000009M9JE.jpg