Convert String value to Float

2 posts, 0 answers
  1. Lukas
    Lukas avatar
    1 posts
    Member since:
    Nov 2018

    Posted 27 Mar Link to this post

    Hello,

    in my project i need to sum values from DB column which contains string values too (column Value (type String)). I have information about type of Value (column Type).

    Please is possible to write expression for conversion Value from type String to type Float and then SUM all this numeric values?

     

    Simplified model:

    ID    Value    Type

    ================

    1      5,21      number

    2      text 1    string

    3      4,56      number

    4      text 2    string

     

    And i need summary: 5,21 + 4,56 = 9,77

    Thanks for any idea.

    Lukas

     

    Telerik Report Designer v11.2.17.1025

     
  2. Neli
    Admin
    Neli avatar
    49 posts

    Posted 29 Mar Link to this post

    Hi Lukas,

    The total can be calculated through the Aggregate function Sum. However, for each value, you need to check the type and if it is a number to convert it to double. The expression might look like: 

    ="Total: " + Sum(CDbl(IIF(Fields.Type = 'number',Fields.Value, 0)))

    The attached report demonstrates the solution. Keep in mind that a CSV data source is used where the double values are separated by a dot (instead 5,21, 5.21 is used).

    Regards,
    Neli
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top