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
365
{System.ArgumentOutOfRangeException using SetMeasureAggregator
posted

Hi folks,

I am trying to test out using a MeasureAggregator, and am getting this exception.  Not sure why the viewModel.Measures array would be empty but it appears to be.  Thoughts?

 
        void DrillDown_Loaded(object sender, RoutedEventArgs e)
        {

            IEnumerable sampleData = SampleDataGenerator.GenerateSales(500);

            //(xamPivotGrid1.DataSource as FlatDataSource).ItemsSource = sampleData;
           
            FlatDataSource flatDataSource = new FlatDataSource()
            {
                //Data is the IEnumerable to be used as a source
                ItemsSource = sampleData,
                Cube = DataSourceBase.GenerateInitialCube("Sale"),
                Rows = DataSourceBase.GenerateInitialItems("[Date]"),
                Columns = DataSourceBase.GenerateInitialItems("[City]"),
                Measures = DataSourceBase.GenerateInitialItems("NumberOfUnits, AmountOfSale")
            };

            xamPivotGrid1.DataSource = flatDataSource;

            xamPivotDataSelector1.DataSource = flatDataSource;

            xamPivotGrid1.DataSource.Columns.CollectionChanged += new NotifyCollectionChangedEventHandler(Columns_CollectionChanged);

            IOlapViewModel viewModel = xamPivotGrid1.DataSource;

            viewModel.SetMeasureAggregator((IMeasureViewModel)viewModel.Measures[0], MeasureAggregator.Average);

            viewModel.RefreshGrid();
        }

 

Parents
No Data
Reply
  • 8831
    posted

    Hello,

    At the moment when you try to access the measure at index 0 the Measures are not initialized yet.
    One thing you can do is to listen for the CollectionChanged event of Measures collection and then you can apply the aggregator you want.
    The better approach I think is to add dimension metadata for this particular measure:

        CubeMetadata cubeMetadata = new CubeMetadata { DataTypeFullName = "[ItemsSourceClassName]", DisplayName = "[CubeDisplayName]" };

        flatDataSource.CubesSettings.Add(cubeMetadata);

        DimensionMetadata numberOfUnitsMetadata = new DimensionMetadata

        {

            SourcePropertyName = "Units",

            DisplayName = "Units (Avg)",

            DimensionType = DimensionType.Measure,

            AggregatorType = AggregatorType.Average,

            DisplayFormat = "{0:0.##}"

        };

        cubeMetadata.DimensionSettings.Add(numberOfUnitsMetadata);

    You can do it from XAML as well.
    Now this measure will be initialized to perform average operations.

    If you want multiple measures over single property then set:

        flatDataSource.DimensionsGenerationMode = DimensionsGenerationMode.Mixed;

    and add the additional metadata for each additional measure you want.

        DimensionMetadata unitsMetadata = new DimensionMetadata

        {

            SourcePropertyName = "Units",

            DimensionType = DimensionType.Measure,

            DisplayFormat = "{0} pcs."

        };

     

        cubeMetadata.DimensionSettings.Add(unitsMetadata);

    And now you will have two measures built over Units property as one of them calculates the average result.

    Best regards.
    PPilev.

Children