How to do easy rankings in SSRS

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:

  1. In Design view, right-click the design surface outside the border of the report and click Report Properties.

  2. Click Code.

  3. In Custom code, type the code. Errors in the code produce warnings when the report runs.

For Visual Studio:
To add code to a report

  1. On the Report menu, click Report Properties.
    NoteNoteIf the Report menu is not available, click within the report design area.
  2. On the Code tab, in Custom code, type the code.

I hope this helps!

About the Author

Samuel Mindlin is a Product Manager and has been with the Mindlin Consulting Group since 2009.

Leave a Reply 0 comments