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);
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.
Hello Andrew,
Thank you for getting back to us. We have seen this and attempted to use it however we still run into a problem.
In our example (see below) there is a list of departments/categories/classes (departments drill down to categories and categories drill down to classes). The first column is a sales value for each department/category/class with the total at the bottom of the column. The second column needs to be a percentage of sales where the value is the dep/cat/class sales value divided by the (grand) total sales from column 1.
Our problem is trying to determine the "sales" value for each row in order to calculate: e.Value = 100 * sales / sales_total.
How do we determine the value of "sales"?
Code:
Private Sub ds_AggregateMeasure(sender As Object, e As AggregateMeasureEventArgs)
For Each o As Object In e.Items
Dim item As cSalesSummaryData_Dept_Cat_Class = TryCast(o, cSalesSummaryData_Dept_Cat_Class)
If item IsNot Nothing Then
sales_total += item.Sales
End If
Next
If e.MeasureDescriptor.Name = "Sales%" Then
If sales_total <> 0 Then
e.Value = 100 * sales / sales_total
e.Handled = True
End Sub