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

Filtered aggregate capability?

1 Answer 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
michael smith
Top achievements
Rank 1
michael smith asked on 08 Jan 2011, 01:37 AM
I have a bound RadGrid which has three columns that are aggregated (Aggregate="Avg") on it. These three columns are of type currency. My challenge here is that the aggregation needs to be conditional based upon the value in the cell. If the value is $0.00, then it should not be included in the Average calculation. I know this seems odd, but it's the request that my users are giving to me.

Take the following example of the data in a segment of the grid

Sale Amount
$45.00
$50.00
$100.00
$0.00
-----------
Avg $48.75

The average calculation will be the sum of fields divided by the row count or (45 + 50 + 100 + 0) / 4 = 48.75

HOWEVER

What my users want is for this calculation to be (45 + 50 + 100 + 0) / 3 = 65  They want the row with $0.00 to not be included in the average calculation.

The documentation for the Aggregate (http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html) has a little tidbit on the first page which *might* be what I'm looking for, but I'm not sure if it is or how to use it:

" RadGrid will calculate aggregates over the entire data source and will respect the filter expression applied (if present)"

Any assistance is very much appreciated!


Thank you,
Michael Smith

1 Answer, 1 is accepted

Sort by
0
Mike Nogen
Top achievements
Rank 1
answered on 08 Jan 2011, 12:40 PM
Take a look at this. It may be a solution.

http://www.telerik.com/community/forums/aspnet/grid/multiple-custom-aggregates-in-group-footer.aspx

And then something like

GridDataItemCollection children = RadGrid1.MasterTableView.Items;
           foreach (GridDataItem childItem in children)
           {
               price = double.Parse(childItem["Price"].Text);
               if (!price.Equals(0))
               {
                   grpverified++;
                   customTotal += price;
               }
               else
               {
                   double priceIsZero = 0;
               }
           }
             
           double avgPriceFooter = customTotal / grpverified;
           RadGrid1.MasterTableView.Columns.FindByUniqueName("Price").FooterText = avgPriceFooter.ToString();
Tags
Grid
Asked by
michael smith
Top achievements
Rank 1
Answers by
Mike Nogen
Top achievements
Rank 1
Share this question
or