I have found this code below to be very helpful when trying to do rankings in SSRS.
Public dim Previousvalue as Integer =0
public dim SourceRank as Integer =1
Public Function Rank(sourceValue as Integer ) As Integer
if Previousvalue >sourceValue
SourceRank =SourceRank +1
else
SourceRank =SourceRank
end if
Previousvalue =sourceValue
return SourceRank
End Function
And in your textbox where you would like to get the rank please put the expression
=code.Rank(Fields!value.Value)
So where do you stick this code to create the function?
For Report Builder:
-
In Design view, right-click the design surface outside the border of the report and click Report Properties.
-
Click Code.
-
In Custom code, type the code. Errors in the code produce warnings when the report runs.
To add code to a report
- On the Report menu, click Report Properties.
NoteIf the Report menu is not available, click within the report design area.
- On the Code tab, in Custom code, type the code.
I hope this helps!