Bartosz
Bartosz

Reputation: 4592

Accessing variable in SSRS function

I have a report which lists items from different categories. Need to display category name only when it changes from the previously listed one. My approach is using a custom function to generate appropriate text, however need to persist the previous value somehow. Wanted to use report variable for that, but I'm not sure how can I set its value and access it within the function? Also, does my approach make any sense, or is there any simpler way of doing it?

Upvotes: 1

Views: 1426

Answers (2)

Bartosz
Bartosz

Reputation: 4592

Sorry, managed to do it the way I wanted. If anyone would have similar issues, this is a function I added to "Code" section:

Public Function GetHeader (val as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable, ByVal header as Int32)

Dim title As String
title = ""

If (val.Value <> header) Then
Select Case header
Case "1" 
title = "header 1"
Case "2" 
title = "header 2"
Case Else 
title = "header last"
End Select
val.Value = header
End If

Return title

End Function

And this is how I call it from expression:

=Code.GetHeader(Variables!Header, Fields!YourProperty.Value)

Upvotes: 1

Tomi Niemenmaa
Tomi Niemenmaa

Reputation: 650

To me it seems you should use row groups. Create a row group by category and add group header that contains your category title. That way you don't need to store the value of the previous categories to see the change but the grouping handles it instead.

Upvotes: 0

Related Questions