ExecuteWithAggregationInfo(DimIndex: Integer; Source: IMatrix; Filter: IDimSelectionSet): IMatrixWithAggregationInfo;
DimIndex. Index of the dimension, by which elements aggregation is executed.
Source. Matrix with source data, based on which aggregation is executed.
Filter. Dimension selection, according to which aggregation is executed.
The ExecuteWithAggregationInfo method calculates aggregated data and allows for getting information about aggregation execution result.
Executing the example requires that repository contains a standard cube with the CUBE identifier. The cube should contain at least two dimensions. The first dimension - MDM dictionary containing with hierarchical element structure and two levels. Cube facts should be added locally without the use of existing dictionary.
Add links to the Cubes, Dimensions, Matrix, Metabase system assemblies.
Sub UserProc;
Var
MB: IMetabase;
CubeInst: ICubeInstance;
Destination: ICubeInstanceDestination;
Man: IMatrixAggregatorManager;
BasicAggr: IBasicMatrixAggregator;
Dims: ICubeInstanceDimensions;
Dim: IDimensionModel;
Lvls: IDimLevels;
LevAggr: IBasicMatrixLevelAggregator;
MatrDS: IMatrixDataSource;
DimSS: IDimSelectionSet;
Matr, MatrAggr: IMatrix;
Iter: IMatrixIterator;
MatrixAggrInfo: IMatrixWithAggregationInfo;
AggrCount, i: Integer;
AggrInfo: IAggregationInfoItem;
Begin
// Get the current repository
MB := MetabaseClass.Active;
// Get opened cube instance
CubeInst := MB.ItemById("CUBE").Open(Null) As ICubeInstance;
// Get cube display version set by default
Destination := CubeInst.Destinations.DefaultDestination;
// Create and set up data aggregator
Man := New MatrixAggregatorManager.Create As IMatrixAggregatorManager;
BasicAggr := Man.CreateAggregator("BasicMatrixAggregator") As IBasicMatrixAggregator;
// Get cube dimensions and display their names
Dims := Destination.Dimensions;
Debug.WriteLine("Cube dimensions:");
For i := 0 To Dims.Count - 1 Do
Debug.WriteLine("- " + Dims.Item(i).Name)
End For;
// Select the second dimension to set up aggregation parameters
Debug.WriteLine("Aggregation parameters are set up for the dimension: " + Dims.Item(1).Name);
// Get second dimension structure
Dim := Dims.Item(1).Dimension;
// Get dimension levels
Lvls := Dim.Levels;
BasicAggr.Dimension := Dim;
// Set consumer level, source level and aggregation method - Sum
LevAggr := BasicAggr.LevelAggregation(Lvls.Item(Lvls.Count - 2));
LevAggr.Operation := BasicAggregatorOperation.Sum;
LevAggr.Include(Lvls.Item(Lvls.Count - 1)) := True;
// Set selection of the first element in the first dimension
MatrDS := Destination As IMatrixDataSource;
DimSS := MatrDS.CreateDimSelectionSet;
DimSS.Item(0).SelectElement(0, True);
// Set full selection for the rest of dimensions
For i := 1 To DimSS.Count - 1 Do
DimSS.Item(i).SelectAll;
End For;
// Calculate matrix according to the specified selection
Matr := MatrDS.Execute(DimSS);
// Get matrix with source data
Iter := Matr.CreateIterator;
Iter.Move(IteratorDirection.First);
Debug.WriteLine("Source data:");
While Iter.Valid Do
Debug.Write(Iter.Value + " ");
Iter.Move(IteratorDirection.Next);
End While;
Debug.WriteLine("");
// Calculate aggregated data
MatrixAggrInfo := BasicAggr.ExecuteWithAggregationInfo(1, Matr, Null);
// Get matrix with aggregated data
MatrAggr := MatrixAggrInfo.Matrix;
Iter := MatrAggr.CreateIterator;
Iter.Move(IteratorDirection.First);
Debug.WriteLine("Aggregated data:");
While Iter.Valid Do
Debug.Write(Iter.Value + " ");
Iter.Move(IteratorDirection.Next);
End While;
Debug.WriteLine("");
// Get aggregation information
AggrInfo := MatrixAggrInfo.Item;
// Get the number of aggregated elements
AggrCount := AggrInfo.Count;
Debug.WriteLine("Number of aggregated elements: " + AggrCount.ToString);
End Sub UserProc;
After executing the operations a cube data aggregator is created. Aggregation will be executed by elements from the second to the first dimension level with the use of the Sum method for calculating basic aggregation mechanism. After the setup is complete, aggregated data is calculated. Source data and aggregated data will be displayed in the console. For example:
Cube dimensions:
- Facts
- Dictionary 1
- Dictionary 2
Aggregation parameters are set up for the dimension: Dictionary 1
Source data:
1 2 3 4 5 6 7 8 9 1 1 1 1 1 1
Aggregated data:
3 2 6 5 9 8
Number of aggregated elements: 6
See also: