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
Weighted Average in xampivotgrid using flatdatasource


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

but the example link provided died and the pasted code has issues.


No Data
  • 255
    Verified Answer
    Offline posted

    (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:

    Using a custom aggregator example with weighted average help class (has some issues but the fix is in a reply)

    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.

    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")
    FlatDataSource dataSource = new FlatDataSource();
    //then set that data soruce to the pivot control

    After that the "test" measure appeared and it has the expected values.