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
No Data
Reply
  • 34690
    Offline posted

    Hello Paul,

    I have been investigating into this requirement that you are looking to achieve, and the custom aggregators work quite a bit differently in the Windows Forms UltraPivotGrid versus the WPF XamPivotGrid. In the UltraPivotGrid, there is an event on the Olap data source named AggregateMeasure that can be used to override the default aggregate functions.

    The event arguments of the AggregateMeasure event returns you the Items to be aggregated, the Measure being aggregated, and allows you to set a Value for that aggregation. As such, you can essentially implement custom aggregation of your UltraPivotGrid measures by using this event.

    Please let me know if you have any other questions or concerns on this matter.

Children