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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tMap Expression Builder - IF-ELSE statements

Hi folks,
Just wondering if it is possible to create if-else statements in the tMap expression builder. If you could give some examples it would be much appreciated.
Thank you in advance!
Labels (2)
14 Replies
alevy
Specialist
Specialist

Certainly is. Use standard Java syntax: <boolean test condition>?<then expression>:else expression. For example:
row1.myKey.equals("FirstValue")?1:0
_AnonymousUser
Specialist III
Specialist III

Thanks. I was also looking for this and it worked fine. Is there a reference for all these syntax. I dont find it in the user guide or reference guide. I am not a java developer and would like to learn these just for the purpose of using talend effectively.
Anonymous
Not applicable
Author

Thanks. I was also looking for this and it worked fine. Is there a reference for all these syntax. I dont find it in the user guide or reference guide. I am not a java developer and would like to learn these just for the purpose of using talend effectively.

Unfortunately, there is no a document for these syntax, but you can always learn these knowledge and experience from Talend forum.
Anonymous
Not applicable
Author

Hi everyone,
How about this expression at tMap? Could you please help me on the Java syntax?
Example expression at output ColumnC,
if row1.Year_ID < 2009
2000+row2.ColumnA
else
2008+row2.ColumnA
For '+', it's concatenating the value rather than actual add operation.
Your help is very much appreciated!
alevy
Specialist
Specialist

Presuming that Year_ID and ColumnA are integers, then just:
row1.Year_ID < 2009 ? 2000+row2.ColumnA : 2008+row2.ColumnA
Anonymous
Not applicable
Author

What if..
Year_ID is int
ColumnA is double
output ColumnC is double
row1.Year_ID < 2009 ? 2000+(Integer.parseInt(row2.ColumnA)) : Integer.parseInt(2008+row2.ColumnA)
I tried but it returns error.
Please help me, thanks!
alevy
Specialist
Specialist

What's the error?!
Anonymous
Not applicable
Author

Hi Alevy,
Sorry, looks like I didn't think hard. tConvertType simply solved my problem.
But I have another problem, what if I have 3 conditions?
Is my design correct?
row1.Year_ID < 2009 ? 2000+row2.F0015 : row1.Year_ID = 2009 ? 2008+row2.F0015 : 2012+row2.F0015

Thanks 😃
Anonymous
Not applicable
Author

hello
can anyone please tell me how to divide a data but not all of them 
for example i've the row 'type' witch content so many informations , i want just the 'type' == "stock" i want to have them like they are but when 'type' != "stock" i want to divide all the datas /7
so Stock is for the weekends and the others are for the days  
thanks