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

Calculate Row in Table

3 Answers 462 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Drew
Top achievements
Rank 1
Drew asked on 27 Dec 2012, 05:41 PM
Is it possible to utilize values that are generated in the report, not associated with the entity?  

For instance, in one row, I calculate the Monthly Average number of occurrences for each column in the report.  I then would like to find the total average.

____________________________________________________________________________________
| Month | [=Fields.Name] | Total |
---------------------------------------------------------------------------------------------------------------------------------------
| [=Field.Date*] | [=Count(Fields.Id)] | [=Count(Fields.Id)] | ---------------------------------------------------------------------------------------------------------------------------------------
| Total | [=Count(Fields.Id)] | [=Count(Fields.Id)] | ---------------------------------------------------------------------------------------------------------------------------------------
| Monthly | [=CDbl(Count(Fields.Id)) /  |    Need Help |
| Average | CDbl(CountDistinct(Fields.Date.Month))] | Here |
---------------------------------------------------------------------------------------------------------------------------------------

Notes:
* Formatted By Month

The problem arises in that an object in the column may not operate on a given month so I don't include it in the average.  My goal, essentially is to find the average of the Monthly Averages, but I cannot figure out how to access the row's data.

3 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 01 Jan 2013, 01:15 PM
Hello Drew,

It is not possible to use fields, calculated in the report, only the ones coming from the data-source. What you need are nested aggregates which are not supported out of the box. Instead you may implement your custom aggregate function that performs average over accumulated averages grouped by some criteria (date in your case). Find attached a sample report demonstrating this idea.
 
All the best,
Elian
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Drew
Top achievements
Rank 1
answered on 04 Jan 2013, 05:43 PM
I think this is what I was looking for.  Along a similar path, is it possible to to pass the objects instead of just a field?

Eg. instead of Fields.Date I would like to get the actual object that could be cast to its actual type.

I tried using ReportItem.DataObject, but I can't seem to get it narrowed down to just the members of the column group.

public void Accumulate(object[] values)
{
    var obj = values[0] as Telerik.Reporting.Processing.IDataGroupMember;
    if (obj == null)
    {
        return;
    }
     
    foreach (var myObject in obj.EnumerateRawData())
    {
        if (!this.myList.Contains((MyObjectType)myObject))
        {
            this.myList.Add((MyObjectType)myObject);
        }
    }
}

The code above includes all of the members instead of just the ones in the column.

I'm trying to repeat the procedure of a nested aggregate function for a column, but I need more information than just a field when processing the data.
0
Drew
Top achievements
Rank 1
answered on 07 Jan 2013, 04:22 PM
I think I got around it by passing the Column Header (Fields.Name) to a custom function to handle the aggregation and used the header to filter all of the objects. 

eg:

=MyCustomCalculateFunction(ReportItem.DataObject, Fields.Name)

public static double MyCustomCalculateFunction(Telerik.Reporting.Processing.IDataGroupMember obj, string name)
        {
              var myListOfObjects = obj.EnumerateRawData().Cast<MyObject>().Where(log => log.Name == name).OrderBy(x => x.Date).ToList());
...
        }
Tags
General Discussions
Asked by
Drew
Top achievements
Rank 1
Answers by
Elian
Telerik team
Drew
Top achievements
Rank 1
Share this question
or