Question

I have a number field in my ssrs report that has multiple values separated by a comma. I want to convert the number to currency but I get an error when the field has more than on value. I'm converting the text box to currency and added the (*) operator to multiply by .01 so my numbers are not inflated. I'm sure the comma is what causing the error as BIDS is expecting a number, but I'm not sure how to write the expression so that it only modifies the numbers in the string.

=Fields!field_A.Value * .01

Field
Number1 = converts to currency($Number1)
Number1, Number2 = #Error
number1, number2, number3 = #error
Was it helpful?

Solution

You can use embedded code in the report to do the processing of the string. This allows you to use the full VB.NET language. From the report menu in SSRS select Report Properties and select the Code section on the left. (This is in VS2010, I'm not sure what version of SSRS you're building in.)

Then you can use a VB.NET function like the one below to do the actual string processing. I'm not sure exactly how you want the output so you'll want to read the MSDN page on the FormatNumber() VB.NET function.

Function ConvertCashString(orig As String)
    Dim newString As String = ""
    For Each s As String In orig.Split(",")
        Dim parsedString As Double
        If (Double.TryParse(s, parsedString)) Then
            newString += "$" + FormatNumber(parsedString * 0.01, 2, TriState.True, TriState.UseDefault, TriState.False) + ", "
        End If
    Next

    Return newString
End Function

Then in the report itself you can call the function like so:

 =Code.ConvertCashString(Fields!dbString.Value)

You should also read the MSDN page: Add Code to a Report (SSRS)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top