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
Thank you for your update on this matter.
I have been going over your most recent update, but I'm not entirely sure I completely understand the structure that you have set up in your UltraPivotGrid data. It sounds like you have the owning "sales" total on perhaps an owning parent data item, but I am not entirely sure in this case. If the data item shows up in the e.Items collection of the event arguments, I would recommend using that, but I'm guessing that it is not showing up in this case.
Still, I would expect that the underlying data items that make up your departments / categories / classes that you are passing to your FlatDataSource in this case are available in your underlying IEnumerable that you pass to the FlatDataSource. I believe you will need to index into this collection and find the Sales value for your particular items.
Again though, I am unsure if I am completely understanding the structure that you have set up in your application. Would it be possible for you to provide an isolated sample project that demonstrates this structure so that I may be able to assist you better in this case?
Thank you once again for the quick response and your assistance. We will take a look at the thread you have recommended.
Regards.
Thank you for your update on this matter. I am glad you were able to work around this issue you were seeing.
Regarding exporting the UltraPivotGrid, this is not currently built-in. If you would like to see exporting functions built into the UltraPivotGrid, I would recommend suggesting a new product idea for this at the Windows Forms ideas site. This will place you in direct communication with our product management teams who plan and prioritize upcoming features and development based on community and user feedback.
With the above said, I did some looking around, and I found a forum thread where it appears that another Infragistics community member created a way to manually export the UltraPivotGrid. I cannot say for certain whether or not this will work for your requirement, but the exact response is from the user "Edgar Victor Zamora" in reply to "Daniel Yuen" about 2 years ago. I hope this helps you.
Thank you for your assistance. We have figured out a work-around for this particular issue.
We have a question about export functionality. Is there a function for exporting to Excel or even CSV?
Thanks again.