Creating a Modeling Variable: Filling the Data from Source

Executing the example requires that the repository contains a modeling container with the Kont_Model identifier and a cube with the Cube_1 identifier. This cube is based on the Calen_1 dictionary and any other dictionaries. The cube contains data of the Half-years level.

Sub Main;

Var

MB: IMetabase;

CrInfo: IMetabaseObjectCreateInfo;

MObj: IMetabaseObject;

MsVar: IMsVariable;

Sampling: IMsVariableSampling;

Cube: IAutoCube;

CubeSource: IAutoCubeSource;

//For aggregation setup by the calendar

AggrManager: MatrixAggregatorManager;

IAggrManager: IMatrixAggregatorManager;

AggrModel: IMatrixAggregatorModel;

BasicAggregator: IBasicMatrixAggregator;

LevelBasicAggregator: IBasicMatrixLevelAggregator;

Dim: IAutoCubeDimension;

DimModel: IDimensionModel;

DimLvl: IDimLevels;

//For data loading

CubeInst: ICubeInstance;

Dest: ICubeInstanceDestination;

DimSS: IDimSelectionSet;

DimS: IDimSelection;

Elem: IDimElementArray;

FixInfo: IAutoCubeSourceFixInfo;

DimFix: IAutoCubeSourceDimensionFix;

i: Integer;

Begin

MB := MetabaseClass.Active;

CrInfo := MB.CreateCreateInfo;

CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_MSVARIABLE;

CrInfo.Id := "Var_3";

CrInfo.Name := Variable #3;

CrInfo.Parent := MB.ItemById("Kont_Model");

MObj := MB.CreateObject(CrInfo).Edit;

MsVar := MObj As IMsVariable;

//Method of filling with data

MsVar.DataFillType := MsVariableDataFillType.DataSource;

Sampling := MsVar.Sampling;

//Calculation step for the variable: Years and Half-years

Sampling.Level(DimCalendarLevel.Year) := True;

Sampling.Level(DimCalendarLevel.HalfYear) := True;

Cube := MsVar.Cube;

//Parameters of aggregation by calendar levels

AggrManager := New MatrixAggregatorManager.Create;

IAggrManager := AggrManager As IMatrixAggregatorManager;

AggrModel := IAggrManager.CreateAggregator("BasicMatrixAggregator");

Dim := Cube.Dimensions.Calendar;

DimModel := Dim.Dimension;

DimLvl := DimModel.Levels;

//Aggregation for calendar dimension

AggrModel.Dimension := DimModel;

BasicAggregator := AggrModel As IBasicMatrixAggregator;

//The level for which aggregation is adjusted is Years level

LevelBasicAggregator := BasicAggregator.LevelAggregation(DimLvl.Item(0));

//Level, which values are used at aggregation is Half-years

LevelBasicAggregator.Include(DimLvl.Item(1)) := True;

//Aggregation method is Sum

LevelBasicAggregator.Operation := BasicAggregatorOperation.Sum;

Dim.Aggregator(Cube.Destinations.Item(0)) := AggrModel;

//Add the source cube to the variable

CubeSource := Cube.Source;

CubeSource.Cube := (MB.ItemById("Cube_1").Bind As ICubeModel).Destinations.DefaultDestination;

//Select the calendar;

CubeSource.Calendar := CubeSource.Cube.Dimensions.FindById("Calen_1");

FixInfo := CubeSource.FixInfo;

//Fix the modifications

For Each DimFix In FixInfo Do

DimFix.Operation := BasicAggregatorOperation.Sum;

DimFix.Selection.SelectAll;

End For;

//Get Instance of the variable cube

CubeInst := (Cube As IMetabaseObject).Open(Null) As ICubeInstance;

Dest := CubeInst.Destinations.DefaultDestination;

//Form SelectionSet for the cube

DimSS := Dest.CreateDimSelectionSet;

//Select the whole Half-years level.

DimS := DimSS.Item(0);

Elem := DimS.Dimension.Levels.Item(1).Elements;

For Each i In Elem Do

DimS.SelectElement(i, False);

End For;

//Select all in the facts dimensions

DimSS.Item(1).SelectAll;

//Load data;

((Cube As IMetabaseObject).Open(Null) As IAutoCubeInstance).UpdateFromSource(DimSS);

MObj.Save;

End Sub Main;

After executing the example a modeling variable is created in the modeling container. The method of filling with data is From Source. Two levels are presented in the variable frequency. They are Years and Half-years. For the Years level of calendar the aggregation is set: Half-year level data is summed. After this the cube, on which the variable is built, is obtained, and data from the source cube is loaded into it.

See also:

Examples