Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Subtracting Previous row with Current row in ABAP CDS View

reachglady
Explorer
0 Kudos

Hi All,

For the below example, how to calculate the Column C in a CDS View?

screenshot-184.png

C1 = A1-B1

C2 = C1-B2

C3=C2-B3 and so on..

Thanks in Advance!

1 REPLY 1

mateuszadamus
Active Contributor
0 Kudos

Hello reachglady

Do you have any record ID in the table? Or a date by which you can sort the records? If yes, then have a look at this example:

SELECT a, b, (a - ISNULL((
      SELECT TOP 1 b 
        FROM table AS t2 
        WHERE t2.id < t1.id
        ORDER BY id DESC), 0) AS c 
  FROM table AS t1

Hope this helps you out.

Kind regards,

Mateusz