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

Aggregate Calculated From Other Aggregates

2 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tye
Top achievements
Rank 1
Tye asked on 24 Feb 2011, 04:20 AM
I searched but couldn't find an answer, so I'm hoping someone can point me in the right direction. 

If I have a grid with 5 columns:

Client Name
Fees 1
Fees 2
Discount
Percentage

Discount is the difference between Fees1 and Fees2 (Fees1 - Fees2). Percentage is Fees1/Fees2. The grid has aggregates for the Fees 1 column, Fees 2 column, and Discount column (these are all Sums). Doing a Sum or Average on the Percentage column will not give me the right number...what I need to do is take the Sum(Fees1)/Sum(Fees2) to get the Average Percentage...

So, is there a way to show an aggregate value for a column (the Average Percentage) that is calculated from the aggregates of other columns? 

Thanks
Tye

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Feb 2011, 06:24 AM
Hello Tye,

Give a try with the following code snippet in itemDataBound to achieve this.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridFooterItem)
        {
            GridFooterItem footerItem = (GridFooterItem)e.Item;
            double sum1 = Convert.ToDouble((footerItem["Fees1"].Text).Split(':')[1]);
            double sum2 = Convert.ToDouble((footerItem["Fees2"].Text).Split(':')[1]);
            footerItem["Percentage"].Text = (sum1 / sum2).ToString();
         }
    }

Thanks,
Princy.
0
Tye
Top achievements
Rank 1
answered on 25 Feb 2011, 04:10 PM
Thanks Princy!
Tags
Grid
Asked by
Tye
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tye
Top achievements
Rank 1
Share this question
or