Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Cumulative sum

Hello,

I'm doing a cumulative sum of the F2 field. But I need that sum to be done independently for each value of the F1 field.

Here is the example :

Capture3.PNG

For F1 = 2, I would like the sum to start again from 0, not from 45.

30

24

34

Here is my script.

Input:

LOAD * INLINE [

    F1, F2, F3

    1, a, 5

    1, b, -10

    1, c, 50

    2, a, 30

    2, b, -6

    2, c, 10

];

Output_temp:

LOAD F1

  ,F2

  ,F3

  ,RangeSum(F3,Peek(F3_Cumul)) as F3_Cumul

RESIDENT Input

ORDER BY F1,F2;

DROP TABLEs Input;

Thank you for your help.

1 Solution

Accepted Solutions
sunny_talwar

Try this:

Input:

LOAD * INLINE [

    F1, F2, F3

    1, a, 5

    1, b, -10

    1, c, 50

    2, a, 30

    2, b, -6

    2, c, 10

];

Output_temp:

LOAD F1

  ,F2

  ,F3

  ,If(Previous(F1) = F1, RangeSum(F3,Peek(F3_Cumul)), F3) as F3_Cumul

RESIDENT Input

ORDER BY F1,F2;

DROP TABLEs Input;


Capture.PNG

View solution in original post

2 Replies
sunny_talwar

Try this:

Input:

LOAD * INLINE [

    F1, F2, F3

    1, a, 5

    1, b, -10

    1, c, 50

    2, a, 30

    2, b, -6

    2, c, 10

];

Output_temp:

LOAD F1

  ,F2

  ,F3

  ,If(Previous(F1) = F1, RangeSum(F3,Peek(F3_Cumul)), F3) as F3_Cumul

RESIDENT Input

ORDER BY F1,F2;

DROP TABLEs Input;


Capture.PNG

Not applicable
Author

Thank you so much again Sunny !

You're the boss !