Example

Oracle Sql

SELECT 
    SUM(SAL) OVER (ORDER BY DATE) CUMSUM,
    SUM(SAL) OVER (PARTITION BY ACCOUNT ORDER BY DATE) CUMSUM_OVER_ACCOUNT,
FROM 
...

R

With a R - Data Table

ledgerExpenseCumulative <- ledgerExpense[,.(amount=sum(amount)),keyby=.(account,date)
    ][,.(date=.SD$date, amount=.SD$amount,cumAmount=cumsum(.SD$amount)),by=.(account)]

where:

  • the first pass calculate the sum of an account for a date and order the set
  • the second pass calculate the cumulatif sum on the partition (.SD) by account