0

I would like to add a discount rate when summing Cashflows over a number of period. To do this I need to multiply each of the remaining cashflows by the discount rate, consummate with this period. I could do this, if I knew the row number of each period, but I can't use it with the window calc I am using. The example below shows the column 'Remaining Interest' which is what I am trying to calculate based on raw data of period and interest.

select Period,RemainingInterest = SUM(PeriodInterestPaid)
OVER (PARTITION BY Name ORDER BY period ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)     
FROM  CF A



Period  Interest   Remaining Interest(Query)       Remaining Interest(Required)
1       1000       1000+2000                       1000/1.02^1+2000/1.02^2 
2       2000       2000                            2000/1.02^1
jedd
  • 420
  • 1
  • 6
  • 13
  • See http://stackoverflow.com/questions/41803909/calculation-in-sql-server/41806985#41806985 looks like very close to what you need – Serg Jan 30 '17 at 12:16
  • @Serg - Thank you, changing the sort order on the linked SQLhas done the trick. – jedd Jan 30 '17 at 17:55

1 Answers1

-1

hi i hope i understand Well --- you need to get the sum of value based on the period that what i under stand from the query but u said that you need a multiply

So there's no need to make a window function just group by

select Period, SUM(PeriodInterestPaid) as RemainingInterest 

FROM  CF A

and if u want a multiplay you will make group by also but u will use anther exp : Pls explan what exactly u need

kareem
  • 1
  • 3