Forum Discussion

StephenMEMC's avatar
StephenMEMC
Advocate I
5 years ago
Solved

Data Table Has Running Total Values - Calculate Single Value?

I hope that makes sense what I'm trying to do. I currently have a table that has values in it but they are already aggregated. So for example:    Month Value January 100 February 250 ...
  • StephenMEMC's avatar
    StephenMEMC
    5 years ago

    For the record, I just went with SQL. It's easier for me there. The code I used is as follows:

     

    CAST(Value - isnull((select top 1 Value
                         from TableView t2
                         where t2.YearMonth < t.YearMonth AND LEFT(t2.YearMonth,4) LIKE LEFT(t.YearMonth, 4) + '%' AND t.Value<>0
                         order by YearMonth desc
                        ), 0) AS decimal(10,2)) AS [MonthValue]

     

    The table has a YYYYMM value in YearMonth and an Index (that I think I can get rid of now)