K. Ventura
K. Ventura

Reputation: 91

SSRS - Add Up Two Placeholders Together

When I add up two textboxes together, I get a weird result...

The total should be $17,496 and not how it's showing up in the image

How do I make it so I only add up the two numbers from the textboxes, and not the two textboxes themselves?

I am using the expression

=ReportItems!all_workers.Value + ReportItems!apprentices.Value

Each textbox (report item) has its own expression of it's own in order to generate the two numbers.

Upvotes: 0

Views: 567

Answers (2)

StevenWhite
StevenWhite

Reputation: 6034

Adding textboxes is generally not a good idea as they can be repeated if they are in a table. What you should do is pull out the expression in each of those placeholders and add them in a new expression in your other textbox. This is a better practice for calculations.

Upvotes: 0

Alan Schofield
Alan Schofield

Reputation: 21738

In your particular scenario you can use an expression like this.

= VAL(
    Mid(
        ReportItems!Textbox1.Value
        , InStr(ReportItems!Textbox1.Value, "=")+1 
        , InStr(ReportItems!Textbox1.Value, ")") - InStr(ReportItems!Textbox1.Value, "=")-1
        )
    )
    +
    VAL(
        Mid(
            ReportItems!Textbox2.Value
            , InStr(ReportItems!Textbox2.Value, "=")+1 
            , InStr(ReportItems!Textbox2.Value, ")") - InStr(ReportItems!Textbox2.Value, "=")-1
            )
        )

However, if you do this kind of thing often, it would better to write a function that returns just the numbers from you string and use that. It will be less work in the long term. There are plenty of examples on how to strip out non-numeric characters from a string. Here's one way of doing it... This returns a string with just the numbers 0-9

Public Function getNumeric(value As String) As String
    Dim output As String
    Dim i  as integer
    For i = 0 To value.Length - 1
        If IsNumeric(value(i)) Then
            output = output + value(i)
        End If
    Next
    Return output
End Function

Your expression is then much simpler.

=Val(Code.getNumeric(ReportItems!Textbox1.Value)) + Val(Code.getNumeric(ReportItems!Textbox2.Value))

Upvotes: 1

Related Questions