I need to write an SSRS expression to check and replace NULL field value with another field value. Can this be done?
If you have to do it a bunch of times, you can also make a reusable function to avoid a lot of typing. Here's a solution modeled off of SQL's ISNULL function:
-
Right click on the Report Document and go to Report Properties.
-
Navigate to the Code tab and add the following function:
Public Function IsNull(input As Object, defaultValue As Object) As Object Return IIf(input Is Nothing, defaultValue, input) End Function
<sup>Note - Even though the custom code is expecting valid VB.NET code, you have to use the
IIF
Ternary operator.</sup> -
Then you can use it in an expression like this:
=Code.IsNull(Fields!MyField.Value,0)