Creating a Calculated Cube

Consider the example of creating a calculated cube using the Fore and Fore.NET language. To create a cube, the following objects must be in the repository:

  1. A cube with the CUBE_SOURCE identifier, which is used as a data source for created calculated cube.

  2. This cube must contain a calendar dimension with the CALENDAR identifier in its structure.

The following example creates a new object that is Calculated Cube in the repository root and sets up its parameters:

To execute the example, add links to the Cubes, Dimensions and Metabase system assemblies. Write the corresponding Imports strings for the Fore.NET example.

Fore Example

Sub CreateCalculatedCube;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    CalcCube: ICalculatedCube;
    CubeModel: ICubeModel;
    CubeDest: ICubeModelDestination;
    CalcSource: ICalculatedCubeSource;
    SourceDim, CalcDim: ICalculatedCubeDimension;
Begin
    MB := MetabaseClass.Active;
    CrInfo := MB.CreateCreateInfo;
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_CALCCUBE;
    CrInfo.Id := "New_Calc_Cube";
    CrInfo.Name := "New calculated cube";
    CrInfo.Parent := MB.Root;
    MObj := MB.CreateObject(CrInfo).Edit;
    CalcCube := MObj As ICalculatedCube;
    //Add the source, which values are used to execute calculations by formulas
    CubeModel := Mb.ItemById("CUBE_SOURCE").Bind As ICubeModel;
    CubeDest := CubeModel.Destinations.DefaultDestination;
    CalcSource := CalcCube.Sources.Add(CubeDest);
    //Add source cube dimensions to calculated cube structure
    For Each SourceDim In CalcSource.Dimensions Do
        CalcDim := CalcCube.Dimensions.Add(SourceDim.Dimension);
        If (SourceDim.Dimension As IMetabaseObject).Id = "CALENDAR" Then
            SourceDim.Fixed := True;
            CalcDim.Fixed := True;
        End If;
    End For;
    MObj.Save;
End Sub CreateCalculatedCube;

Fore.NET Example

Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Metabase;

Sub CreateCalculatedCube(MB: IMetabase);
Var
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    CalcCube: ICalculatedCube;
    CubeModel: ICubeModel;
    CubeDest: ICubeModelDestination;
    CalcSource: ICalculatedCubeSource;
    SourceDim, CalcDim: ICalculatedCubeDimension;
Begin
    CrInfo := MB.CreateCreateInfo();
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_CALCCUBE As Integer;
    CrInfo.Id := "New_Calc_Cube";
    CrInfo.Name := "New calculated cube";
    CrInfo.Parent := MB.Root;
    MObj := MB.CreateObject(CrInfo).Edit();
    CalcCube := MObj As ICalculatedCube;
    //Add the source, which values are used to execute calculations by formulas
    CubeModel := Mb.ItemById["CUBE_SOURCE"].Bind() As ICubeModel;
    CubeDest := CubeModel.Destinations.DefaultDestination;
    CalcSource := CalcCube.Sources.Add(CubeDest);
    //Add source cube dimensions to calculated cube structure
    For Each SourceDim In CalcSource.Dimensions Do
        CalcDim := CalcCube.Dimensions.Add(SourceDim.Dimension);
        If (SourceDim.Dimension As IMetabaseObject).Id = "CALENDAR" Then
            SourceDim.Fixed := True;
            CalcDim.Fixed := True;
        End If;
    End For;
    MObj.Save();
End Sub;

See also:

Examples