Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Windows Forms Custom Aggregator for Pivot Grid
posted

The sample code below was provided by Infragistics support as a solution that works with WPF (www.infragistics.com/.../xampivotgrid-custom-aggregator-wfp) but we need to make this work with Windows Forms.

We have just started using 2018.1 and are new to the Pivot Grid control so would appreciate any assistance with this.

using Infragistics.Olap;

using Infragistics.Olap.FlatData;

 

namespace CustomAggregatorSample

{

    public class GrossProfitAggregator : Aggregator<double>

    {

        private FlatDataSource _flatDataSource;

        private IAggregateable _salesMeasure;

 

        public GrossProfitAggregator(FlatDataSource flatDataSource)

        {

            this._flatDataSource = flatDataSource;

            this._flatDataSource.Initialized += this.DataSource_Initialized;

        }

 

        private void DataSource_Initialized(object sender, EventArgs e)

        {

            // get other aggregateables you are interested in

            this._salesMeasure = (IAggregateable)this._flatDataSource.Cube.Measures["SalesAmount"];

        }

 

        public override IAggregationResult<double, double> Evaluate(IAggregationResult<double, double> oldResult, double value)

        {

            throw new NotImplementedException();

        }

 

        public override IAggregationResult<double, double> Evaluate(IAggregationResult<double, double> oldResult, IAggregateable aggregateable, System.Collections.IEnumerable items)

        {

            double grossProfit = 0;

            double sales = 0;

 

            // iterate through all items that participate in this cell

            foreach (var item in items)

            {

                // aggregateable points to GrossProfit property because

                // in this measure dimension metadata SourcePropertyName = "GrossProfit"

                grossProfit += (double)aggregateable.GetValue(item);

                sales += (double) this._salesMeasure.GetValue(item);

            }

 

            double result = grossProfit/sales;

            return new SingleResult<double>(result);

        }

    }

}

Parents Reply Children