Events
Mar 31, 11 PM - Apr 2, 11 PM
The ultimate Microsoft Fabric, Power BI, SQL, and AI community-led event. March 31 to April 2, 2025.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to: Microsoft Report Builder (SSRS) Power BI Report Builder Report Designer in SQL Server Data Tools
In any expression, you can call your own custom code in a paginated report. You can provide code in the following two ways:
Embed code written in Visual Basic directly in your report. If your code refers to a Microsoft .NET Framework that isn't Math or Convert, you must add the reference to the report. For more information, see Add an assembly reference to a report (SSRS). For more information about other references you can make from your code, see Custom code and assembly references in Expressions in Report Designer.
Provide a custom code assembly by using the .NET Framework. If you provide a custom assembly, you must install it on both the computer where you author the report and the report server where you view the report. For more information, see Use custom assemblies with reports.
In Design view, right-click the design surface outside the border of the report and select Report Properties.
Select Code.
In Custom code, enter the code. Errors in the code produce warnings when the report runs. The following example creates a custom function named ChangeWord
that replaces the word Bike
with Bicycle
.
Public Function ChangeWord(ByVal s As String) As String
Dim strBuilder As New System.Text.StringBuilder(s)
If s.Contains("Bike") Then
strBuilder.Replace("Bike", "Bicycle")
Return strBuilder.ToString()
Else : Return s
End If
End Function
The following example shows how to pass a dataset field named Category to this function in an expression:
=Code.ChangeWord(Fields!Category.Value)
If you add this expression to a table cell that displays category values, whenever the word Bike
is in the dataset field for that row, the table cell value displays the word Bicycle
instead.
Events
Mar 31, 11 PM - Apr 2, 11 PM
The ultimate Microsoft Fabric, Power BI, SQL, and AI community-led event. March 31 to April 2, 2025.
Register today