on 02-10-2023 4:41 PM
Hi,
I want to calculate the running sum of certain column values in BODS/SAP Data Services.
As mentioned in the below example LRP value needs to be sum up for each row(Running_Sum_LRP) and the group by LOB.Can anyone help me with custom function as far I know there is no built-in-function available.
Thanks,
Malini
Greetings malinisomu,
If you have fewer distinct LOBs you can do the following
In the above example, you only have two LOBs
$LRP_ABC
$LRP_IRST
# cumulative sum of the ABC LOB
$LRP_ABC = 0;
# cumulative sum of the ABC IRST
$LRP_IRST = 0;
begin
# check if LOB name = 'ABC'
if ($LOB = 'ABC')
# If Yes, set add the current value of the ABC 's LOB value and the previous value
# previous in this case being $LRP_ABC
begin
$LRP_ABC = $LOB_CURRENT_VAL + $LRP_ABC ;
print($LOB || ', ' || $LOB_CURRENT_VAL || ', ' || $LRP_ABC);
# set the current value equals to the sum of current and previous
$LOB_CURRENT_VAL = $LRP_ABC;
end
# check if LOB name = 'IRST'
if ($LOB = 'IRST')
# If Yes, set add the current value of the IRST 's LOB value and the previous value
# previous in this case being $LRP_IRST
begin
$LRP_IRST = $LOB_CURRENT_VAL + $LRP_IRST ;
print($LOB || ', ' || $LOB_CURRENT_VAL || ', ' || $LRP_IRST);
# set the current value equals to the sum of current and previous
$LOB_CURRENT_VAL = $LRP_IRST;
end
# Return the current
Return $LOB_CURRENT_VAL;
end
Best Regards,
Joseph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
10 | |
8 | |
6 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.