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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

IF/else statement usage in tMap

Hi - I have a problem in applying the if/else condition in tMap. I am trying to do below validations in tMap.
if (in.stop_seq == 1 && in.message_status == 10 && in.message_type == 40) 'AA'
else if (in.stop_seq == 1 && in.message_status == 10 && in.message_type == 45) 'X3'
else if (in.stop_seq == 1 && in.message_status == 10 && in.message_type == 50) 'AF'
else if (in.stop_seq == 2 && in.message_status == 10 && in.message_type == 40) 'AB'
else if (in.stop_seq == 2 && in.message_status == 10 && in.message_type == 45) 'X1'
else if (in.stop_seq == 2 && in.message_status == 10 && in.message_type == 50) 'CD'
My source is a db2 and trying to populate a output filed based on this condition. As am new to this, tried all possible options but didn't work. Could you please help?
Note:In my screenshot attached, i tried with one input value to check and populate the target.
Thanks in advance!!!

Labels (2)
32 Replies
Anonymous
Not applicable
Author

Hi Kiran,
Seems everything ok but  add row1.HIRE_DATE.compareTo(row2.HIRE_DATE)!=0  in your expression.
Then your Expression became  like below after include  above logic.
row1.DEPARTMENT_ID!=row2.DEPARTMENT_ID ? "Error_1" :
row1.DEPARTMENT_ID ==row2.DEPARTMENT_ID ? null :
row1.JOB_ID !=row3.JOB_ID ? "Error_2" :
row1.JOB_ID ==row3.JOB_ID ? null :
row1.HIRE_DATE.compareTo(row2.HIRE_DATE)!=0? "Error_3" :null 
Regards,
Kumar
Anonymous
Not applicable
Author

Hi  salvekaran_1,

                         I think u meant to say that, filtering based on ur 5 condition using expression filter ?? if so ur doing it in wrong way
Anonymous
Not applicable
Author

try below statement

Employees.Department_id != Department.Department_id? "Department ID is not valid" : Employees.Department_id == Department.Department_id? "null": Employees.Job_Id != Jobs.Job_Id? " Job ID is not Valid":Employees.Job_Id == Jobs.Job_Id?"null":"null"
Anonymous
Not applicable
Author

Hi Umesh,
I tried above statement in tMap Expression but it's not working properly please check below screenshot
Anonymous
Not applicable
Author

Hi,
I have situation in tMap.
I have 2 columns STARTDATE & ENDDATE . i just want to validate that STARTDATE should not be greater than ENDDATE &
ENDDATE should not be less than STARTDATE. 
WILL YOU PLEASE HELP ME TO IMPLEMENT THIS LOGIC.
Both columns are type DATE .
Thanx in advance.
0683p000009MACn.png
Anonymous
Not applicable
Author

you can use below function to check whether your date is greater than End date or not. 
Operation: StartDate>EndDate && EndDate>StartDate
row4.STARTDATE != null && (row2.STARTDATE.before(row4.ENDDATE)) 

This will check whether Start Date is before ENDDATE. that means it is lesser than EndDate. 
You can check other Date functions here. talend-date-routine-function-with-examples
Anonymous
Not applicable
Author

Hi Shri_Kul1,
You can create a tMap variable to carry out the logic on the dates and then use that variable to direct the flow to the output table you want.
Please see my screenshot for detail. Feel free to let us know if it is OK with you. 0683p000009MACj.png
Best regards
Sabrina
Anonymous
Not applicable
Author

Hi Sabrina & Umesh ,
Actual scenario is .... the fields i have mentioned  (STARTDATE    &    ENDDATE) are coming from the same table , there is no look up table , but there is 2 target table that are for good data and for bad data, 
in Bad data table there should be only null or the data which is failed at the validation .
so in this case i want "Start Date should not be greater than End date " & "End date should be greater than Start Date" @ the Bad table.
Fields datatype is "Date"  in source table .
waiting for reply...!!!! 0683p000009MACn.png
Thanks
Anonymous
Not applicable
Author

In that case you can use below statement respectively for each good and bad flow. 
This one is for Good Data. 
row4.STARTDATE != null && (row2.STARTDATE.before(row4.ENDDATE)) 

And this one is for bad data. 
(row4.STARTDATE != null && (row2.STARTDATE.after(row4.ENDDATE))) || row4.STARTDATE == null

Hope this will solve your problem. 
Anonymous
Not applicable
Author

Its Working ....
Thanx Umesh... 0683p000009MACn.png