Quantcast
Channel: SCN : All Content - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6745

How to calculate Surplus w.r.t the previously changed value?

$
0
0

Dear Team,

 

I have a scenario where I need to calculate the surplus/ shortage as (Surplus of previous entry - Pegging Qty of current entry). The values are already available with me. But since there is a change in one of the entries(2nd entry below) I need to re-calculate for all the following entries.

 

Recpt Qty     Pegg Qty     Surplus

1000               287               713

1000               0                    713  = Entry which is changed from 427

1000               300               700

1000               200               500

 

The result should look like this:

 

Recpt Qty     Pegg Qty     Surplus

1000               287               713    <== 1000 - 287

1000               0                    713    <== 713 - 0

1000               300               413    <== 713 - 300

1000               200               213    <== 413 - 200

 

I am using the LAG window function to get the previous value. When I come to the 4th entry the calculation goes 700 - 200 = 500, whereas it should be 413 - 200 = 213. The LAG window function will take the previous entry from the table, but I need to consider the changed previous entry.

How can I approach !!!

 

Thanks in advance.

Mayur


Viewing all articles
Browse latest Browse all 6745

Trending Articles