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

need Aggregate function that uses sum of other aggregate functions

3 Answers 252 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brian Graves
Top achievements
Rank 1
Brian Graves asked on 29 May 2010, 09:45 PM
I have several columns that need aggregates functions using the aggregate results of 2 other columns.  For instance, column 1's aggregate function needs to take the sum of column 2 and divide it by the sum of column 3.  Columns 2 and 3 use the SumFunction...example:
var sumFunction = new SumFunction();
sumFunction.FunctionName = "SumColumn2";
sumFunction.SourceField = "Column2";
col.AggregateFunctions.Add(sumFunction);

...so they are calculated when binding occurs.  Therefore, I have to calculate column 1 and put it in my footer AFTER I set my ItemsSource in the datagrid:
_dg.ItemsSource = datalist;
object value = (Convert.ToDouble(_dg.AggregateResults["SumColumn2"].Value) / Convert.ToDouble(_dg.AggregateResults["SumColumn3"].Value)) * 100;
_dg.Columns["Column1"].Footer = String.Format("{0:F2}", value);

This is fine for showing my footer summary.  However, my group aggregate footer column is blank since it is part of my GridViewGroupRow...not my Footer.  Basically, I can't use this approach anymore since columns 2 and 3 show up fine for my group aggregate footer columns...so I'm assuming for column 1 that I need to create my own custom aggregate function.  However, how can I get my custom aggregate function to look at _dg.AggregateResults if they aren't calculated yet?  Please let me know the proper way of handling this issue.  Thanks in advance.  :)

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 02 Jun 2010, 12:50 PM
Hello Brian Graves,

Can you please check the solutions in this forum thread:
how can I mimic Excel's SUMPRODUCT for my footer?


Greetings,
Veskoni
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Arun
Top achievements
Rank 1
answered on 18 Aug 2010, 05:19 PM
HI Veskoni,

I am facing the exact same issue as Brian.

In my case, I have revenue and usage information in column A and B respectively, and I am trying to find rate( in column C)=revenue/usage. 
I am able to get  the group footer sum value for A and B column, but I cannot figure out a way to find the average "rate" in column C's group footer, which would be equal to total revenue/total usage.
I tried using the solution you suggested( http://www.telerik.com/community/forums/silverlight/gridview/how-can-i-mimic-excel-s-sumproduct-for-my-footer.aspx). I cannot implement it because of the constraint I have with my business object.

I found this code snippet which would work for ASP for setting the group footer with calculated value programatically, but I cannot figure out the equivalent for silverlight RadGridView
grd_ItemDataBound(object sender,GridItemEventArgs e)
 {
    //catch the footer element
    if(e.Item.ItemType==GridItemType.GroupFooter)
      { (e.Item.FindControl("yourTextBox") as TextBox).Text = your calculated value }
 }
I can calculate the average rate by using total revenue and total rate by accessing the group footers for revenue and usage columns. It would be great if you could provide me the silverlight equivalent for the above snippet.

Thanks in advance,

Arun Nair
0
Kevin Tran
Top achievements
Rank 1
answered on 16 Sep 2010, 12:48 PM
Hey,
 did you solved this issue , i too struck with the same

Thanks
Tags
GridView
Asked by
Brian Graves
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Arun
Top achievements
Rank 1
Kevin Tran
Top achievements
Rank 1
Share this question
or