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

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://es.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

Parents
  • 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:

    https://es.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://es.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.

    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.

Reply Children
No Data