Sum of multiple data source items.

4 posts, 0 answers
  1. Janitha
    Janitha avatar
    14 posts
    Member since:
    Mar 2018

    Posted 10 Feb Link to this post

    Hi,

    I have created a report based on a CSV data source. This data source has two columns where there is one field called 'Quantity'. In the report, I have a text box item which displays the sum of the quantity where I need to take the sum of the CSV data source 'Quantity' field. I can not configure the data source to send the sum of the quantities beforehand so I need to do this sum in the rendering process of the report. Is there a function where I can achieve this?

    Thank you. 

  2. Neli
    Admin
    Neli avatar
    49 posts

    Posted 13 Feb Link to this post

    Hi Janitha,

    If I understood correctly, you would like to have the Sum of the Quantity Field. This can happen through Aggregate function.
    Insert the following expression in the corresponding text box: 
    = Sum(Fields.Quantity)

    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
  3. Janitha
    Janitha avatar
    14 posts
    Member since:
    Mar 2018

    Posted 13 Feb Link to this post

    Hi Neli,

    That is not the functionality I would like to achieve. Rather than taking the sum of a single field I want to take the sum of all the fields in that specific column. 

    Ex :- Imagine the CSV datasource as below.

    ID, Quantity

    AA,4

    AB,6

    AC,10

    Now when Telerik binding the data to the report it goes through CSV fields one by one. So when using Sum() function it will return 3 values, 4,6 and 10. I want it to return only one value which must be the sum of all the fields in the Quantity column(20). 

     

  4. Neli
    Admin
    Neli avatar
    49 posts

    Posted 15 Feb Link to this post

    Hello Janitha,

    I noticed that you have opened a Support ticket on the same topic. I have answered your questions there. I will summarize my response also in this thread for the benefit of our community.

    The detail section of any data item is rendered as many times as the number of records you have in the corresponding data source. The data scope in the detail section is the current data record, i.e. a single row of data. Therefore, the Sum function will aggregate over this single value and will return the value itself.

    What you need to do is to add a Static group to the data item. The scope of the static group contains all the data in the data item (its parent). The group header and footer sections are rendered only once. Hence, you may place the aggregate function in the group footer to display the total once for the entire Table/List.

    The attached report demonstrates the approach.

    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