Reporting services difference between rows
I have a datatable in reporting services report with a single column which holds integer values.
I want to work out the integer difference + or - between the row and the previous row and display that value in a second column.
i.e
Col1 Col2
1 0
3 2
5 2
1 -4
8 7
I think it may be possible usine the code behind the report using a function but am unsure how to make it work.
I have made a start but am struggling with what im actually trying to do in code.
Any help please.
Code:
Function CalcChangeInAvailable(ByVal RecsTot As integer, ByVal RecsAvail As integer, ByVal rowNum as Integer) As Decimal
if rowNum <=0 then
CalcChangeInAvailable = 0
else
redim RecordsAvailable(rowNum)
RecordsAvailable(rowNum) = RecsAvail
Recs = RecsAvail(rowNum-1) - rowNum
CalcChangeInAvailable = Recs
end if
End Function
Re: Reporting services difference between rows
Code:
Dim RecordsAvailable() As integer
Dim Recs As integer = 0
Dim LastRecs As integer = 0
Dim NowRecs As integer = 0
Dim CurrentRow As integer = 0
Dim PreviousRow As integer = 0
Function CalcChangeInAvailable(ByVal RecsAvail As integer, ByVal rowNum as Integer) As integer
CurrentRow = rowNum
PreviousRow = CurrentRow -1
if CurrentRow <=0 then
CalcChangeInAvailable = 0
else
redim RecordsAvailable(CurrentRow)
RecordsAvailable(CurrentRow) = RecsAvail
LastRecs = RecordsAvailable(PreviousRow)
NowRecs = RecordsAvailable(CurrentRow)
Recs = LastRecs - NowRecs
CalcChangeInAvailable = LastRecs
end if
End Function
I think im nearly there but the LastRecs value always seems to be 0