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

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tMap if condition

Hi Everyone!

 

I am trying to do an if statement in the tMap component in Talend and it seems that I am just getting nulls back with my calculation. I am doing an exercise where I have to change the 1st number of the row to 19 or 20 based on the number. If the 1st number == 1 then replace it with 20 and if the 1st number == 0 replace it with 19. I will then convert the outputted number to a different date format. The data type is currently a string.

 

Example:

1040202 --> 20040202 --> 2004-02-02
0990930 --> 19990930 --> 1999-09-30
1141030 --> 20141030 --> 2014-10-30
1090613 --> 20090613 --> 2009-06-13

 

The Calculation I am currently using is to get to the second step in the proccess (replacing 0 to 19 and 1 to 20):

StringHandling.LEFT(row1.date,1)=="1"? StringHandling.EREPLACE(row1.date,StringHandling.LEFT(row1.date,1),"20"):
StringHandling.LEFT(row1.date,1)=="0"? StringHandling.EREPLACE(row1.date,StringHandling.LEFT(row1.date,1),"19"):null

 

I split up the calculation to see where I am going wrong, but I am not sure where my errors are coming from. I separated the formulas and did:

SEE ATTACHED PHOTO

Left1= StringHandling.LEFT(row1.date,1) -- WORKS

Left1PartialCondition = StringHandling.LEFT(row1.date,1)=="1"?"20":null -- DOESN'T WORK (receiving nulls for all)

 

If someone can give me some input, that would be greatly appreciated as I did look all over community to try and solve this problem.

 

Thanks in advance!

Labels (2)
1 Solution

Accepted Solutions
cmendels
Contributor III
Contributor III

EREPLACE replaces all instances of the string, so you might want to do "20"+row1.date1.substring(1).

View solution in original post

4 Replies
cmendels
Contributor III
Contributor III

When you compare strings in Java, you need to use .equals(). So, your condition would be StringHandling.LEFT(row1.date,1).equals("1").

Anonymous
Not applicable
Author

Hi,

 

Thank you for your response! So,  I tried doing that in the formula and the 19 and 20 is repeating in the date and not just for the 1st left character.

0683p000009M92S.png

StringHandling.LEFT(row1.date,1).equals("1")? StringHandling.EREPLACE(row1.date,StringHandling.LEFT(row1.date,1),"20"):
StringHandling.LEFT(row1.date,1).equals("0")? StringHandling.EREPLACE(row1.date,StringHandling.LEFT(row1.date,1),"19"):row1.date

cmendels
Contributor III
Contributor III

EREPLACE replaces all instances of the string, so you might want to do "20"+row1.date1.substring(1).

Anonymous
Not applicable
Author

Thank you so much!! Got it to work.