Hi,
I've got a XamPivotGrid with a FlatDataSource working and I haven't been able to get the custom/ calculated measures working.
I need to achieve a weighted sum where the values and the weights are two measures present on the pivot table.
I was following the response from https://ko.infragistics.com/community/forums/f/ultimate-ui-for-wpf/45131/calculated-custom-measures-for-flatdatasource-in-xampivotgrid?ReplySortBy=CreatedDate
but the example link provided died and the pasted code has issues.
thanks
(I wrote a reply and somehow it didn't got posted, so here I go again)
Turns out, it can be done.
I managed to get a weighted average by setting a custom aggregator.
First some sources:
How to setup custom aggregators:
https://ko.infragistics.com/help/wpf/xampivotgrid-us-customaggregators
Using a custom aggregator example with weighted average help class (has some issues but the fix is in a reply)
https://ko.infragistics.com/community/forums/f/ultimate-ui-for-wpf/45131/calculated-custom-measures-for-flatdatasource-in-xampivotgrid/331675#331675
what is missing from there is how the custom aggregator is actually set into the FlatDataSource. The example calls for flatDataSource.CubesSettings[0] but that was null at the moment.
flatDataSource.CubesSettings[0] but that was null at the moment.
So what was missing is this:
CubeMetadata cube = new CubeMetadata(); //weirdType is a dynamicaly created type. Use typeof(*your data source type*).FullName cube.DataTypeFullName = weirdType.FullName; cube.DisplayName = "weird type"; DimensionMetadata testMetadata = new DimensionMetadata { SourcePropertyName = "valueProp", DisplayName = "test", DimensionType = DimensionType.Measure, Aggregator = new IgWeightedAverageAggregator("valueProp", "weightProp") }; cube.DimensionSettings.Add(testMetadata); FlatDataSource dataSource = new FlatDataSource(); dataSource.CubesSettings.Add(cube); //then set that data soruce to the pivot control
After that the "test" measure appeared and it has the expected values.
Great job! Let us know if you have any additional questions.