Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

for each row,calculate the sum for four rows below the current row?

Hello All,

I have a small problem . I have two columns..week and item_demand. now for each week, I want to calculate the sum of demands for next four weeks. as given below. There should also be a column indicating whether we have sufficient rows below the current row....i.e four or more rows below the current row

Original table

week     item_demand

1               5

2               6

3               1

4               4

5               8

6               3

7               4

I want the above table to be like

week     item_demand     sum_for_bext_four_weeks       atleast_for_rows_below

1               5                              19                                                Y

2               6                              16                                                Y

3               1                              19                                                Y

4               4                                                                                  N

5               8

6               3

7               4

one more thing. If there are less than four weeks below the current row, then stop calculating it or just keep null there. there should not be any value then. or we can just put another column which indicates if we have less than four rows below the current one or more than four rows below the current row

Thanks

Arif

3 Replies
Anonymous
Not applicable
Author

Hey Arif,

Please see attached example if that's close to what you're looking for.

Not applicable
Author

Hello,

Thanks for your response. Yes this is what i want, but i want this to be done in the script since there are some further calculation to be made on this. Can you please provide the solution using the load script.

Your help is well appreciated

Thanks

Arif

nagaiank
Specialist III
Specialist III

One way of doing the same using load script is attached.