Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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 :
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.
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;
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;
Thank you so much again Sunny !
You're the boss !