Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to get previous row (tuple)'s value without using Custom Code components?

I want to use the previous tuple(s)' value in an expression in tMap.

 

For eg.,

 

Input:

A   |   2

B   |   1

C   |   4

D   |   1

E   |    3

 

Output (previous 2 tuples added):

A   |   2   |   2

B   |   1   |   3

C   |   4   |   7

D   |   1   |   6

E   |   3   |   8

 

How to extract it in tMap expression? Or is there any other component to do it? I do not want to use stuff like tJavaXXXX or tPerlXXXX etc Custom Code or Database query components, which are shortcuts.

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

To do this in a tMap you can use the tMap variables. These are more powerful than they look because of two key features; they keep their values between rows and they are processed from top to bottom in order. As such you can configure them to hold the last value of individual columns and compare them against the current value. 

 

Below is an example of how this can be done......

0683p000009LycL.png

Notice the order in which the variables are assigned and how the _last variables (representing the last row) are set by the _this variables (which are actually set by the current row) before those variables are set by the current row. 

 

 

View solution in original post

19 Replies
manodwhb
Champion II
Champion II

@TalendSpree,are you looking for the below one?0683p000009LyfY.png

Anonymous
Not applicable
Author

@manodwhb This is an accumulation of all previous values. What I'm looking for is a cumulative sum of previous 'n' values. Thanks for taking the time to implement my problem, though!

SachinD
Creator
Creator

Hi @TalendSpree

 

I achieved this using tMemorize and tJavaFlex but as you have mentioned you want the solution without using tJavaFlex code. 

 

0683p000009LygH.jpg

 

Sachin D

Anonymous
Not applicable
Author

@SachinD Thanks for taking the time to implement my problem! I would actually like to know how you're using `tMemorizeRows` and it's output in `tJavaFlex`.

SachinD
Creator
Creator

Thanks @TalendSpree 

 

Please check below screenshots.

I quickly tried it, if you need you can change little code in tJavaFlex if required.

 

0683p000009LyDq.jpg0683p000009Lvzn.jpg0683p000009Lyjz.jpg0683p000009Lyk9.jpg

Thanks,

 

 

click Accept the solution if it helps
and
kudos are welcome when a reply is helpful.

 

Sachin D

Anonymous
Not applicable
Author

To do this in a tMap you can use the tMap variables. These are more powerful than they look because of two key features; they keep their values between rows and they are processed from top to bottom in order. As such you can configure them to hold the last value of individual columns and compare them against the current value. 

 

Below is an example of how this can be done......

0683p000009LycL.png

Notice the order in which the variables are assigned and how the _last variables (representing the last row) are set by the _this variables (which are actually set by the current row) before those variables are set by the current row. 

 

 

Anonymous
Not applicable
Author

Thanks @SachinD ... can we use `globalMap("tMemRows")` in `tMap` component? I've tried, but I get the following error.

Exception in component tMap_1 (tMemRows)
java.lang.NullPointerException
at local_project.tmemrows_0_1.tMemRows.tFileInputDelimited_1Process(tMemRows.java:1126)
at local_project.tmemrows_0_1.tMemRows.runJobInTOS(tMemRows.java:1669)
at local_project.tmemrows_0_1.tMemRows.main(tMemRows.java:1518)

 

 

@rhall Thank you for the help! This is closest to what I was looking for. Only issue is, if I want to change the number of accumulations, I'll have to do it manually. Any suggestions?

 

 

Anonymous
Not applicable
Author

What do you mean by the number of accumulations? Do you mean the number of held rows or the number of columns to hold? You can achieve increases in both, but you are right that you will have to do it manually. This is where you have to decide which is the best approach to take; to use other components (like the memorize rows component) and a bit of Java or keep it all in the tMap. This is why I like Talend because you have this choice 🙂

Anonymous
Not applicable
Author

Thanks @rhall ! I meant increase the number of rows.

Do you have any other tips & tricks on Talend components? 0683p000009MACJ.png