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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
diogenes
Partner - Contributor II
Partner - Contributor II

rolling or cumulative sum

Hi,

I'm relatively new to Talend and looking for an way to create a rolling or cumulative sum over different groups. For example:

Input:

Groups|Value

A| 1

A| 0

A|1

B|2

B|0

C|3

 

Output:

Groups|Value|C_Sum

A| 1|1

A| 0|1

A|1|2

B|2|2

B|0|2

C|3|3

Thanks for your help!

Labels (1)
  • v6.x

1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi,

 

You can do this using a tJavaFlex component:

 

0683p000009LrRA.png

 

I'm using a tFixedFlowInput to simulate the data, as per your example:

 

0683p000009LrNU.png

 

Add the C_Sum column to the schema of your tJavaFlex component:

 

0683p000009LrRF.png

 

Then add the code:

 

 

 0683p000009LrRK.png

 

I've included the code here, so you can just copy and paste it into your job:

 

String  lastGroup = "!";
Integer total = 0;

 

if (!lastGroup.equals(row1.Groups)) {
total = 0;
lastGroup = row1.Groups;
}

total += row1.Value;

row2.C_Sum = total;

 

It's essential that the data is sorted by Groups, but from what you're looking to achieve, I'd expect this to be the case anyway.

 

Regards,

 

 

Chris

View solution in original post

2 Replies
Anonymous
Not applicable

Hi,

 

You can do this using a tJavaFlex component:

 

0683p000009LrRA.png

 

I'm using a tFixedFlowInput to simulate the data, as per your example:

 

0683p000009LrNU.png

 

Add the C_Sum column to the schema of your tJavaFlex component:

 

0683p000009LrRF.png

 

Then add the code:

 

 

 0683p000009LrRK.png

 

I've included the code here, so you can just copy and paste it into your job:

 

String  lastGroup = "!";
Integer total = 0;

 

if (!lastGroup.equals(row1.Groups)) {
total = 0;
lastGroup = row1.Groups;
}

total += row1.Value;

row2.C_Sum = total;

 

It's essential that the data is sorted by Groups, but from what you're looking to achieve, I'd expect this to be the case anyway.

 

Regards,

 

 

Chris

lokeshbabu
Contributor
Contributor

Hi All,

 

Need talned job for below Source .

 

Input Source:

 

Quater |  PPID | Values

14-Q1  | 1         |  10

14-Q2  |  1        | null

14-Q3  | 1         | null

14-Q4  |  1        | 20

 

Output :

 

Quater |  PPID | Values

14-Q1  | 1         |  10

14-Q2  |  1        |  10

14-Q3  | 1         | 10

14-Q4  |  1        | 20

 

for missing Quaters need to populate previous value .

 

Please give me solution.