This is a migrated thread and some comments may be shown as answers.

Sum of multiple data source items.

3 Answers 65 Views
This is a migrated thread and some comments may be shown as answers.
Janitha
Top achievements
Rank 1
Janitha asked on 11 Feb 2019, 05:50 AM

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. 

3 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 13 Feb 2019, 01:03 PM
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
0
Janitha
Top achievements
Rank 1
answered on 14 Feb 2019, 04:23 AM

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. 

- Imagine the CSV 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). 

 

0
Neli
Telerik team
answered on 15 Feb 2019, 04:36 PM
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
Asked by
Janitha
Top achievements
Rank 1
Answers by
Neli
Telerik team
Janitha
Top achievements
Rank 1
Share this question
or