Setting Up Controlling Dimensions for Parameterization of Multidimensional Calculation

Executing the example requires that the repository contains a database with the DB identifier, standard parametric cubes with the CUBE_DEST and CUBE_SOUR identifiers. The CUBE_DEST cube as a fact must use a dictionary with the PARAM_DICT identifier.

Sub UserProc;
Var
    Mb: IMetabase;
    dMd: IMetabaseObjectDescriptor;
    MDcalc: IMDCalculation;
    FormulasTable: IMDCalculationFormulasTable;
    TableForFormulas: ITable;
    destination: IMDCalculationDestination;
    source: IMDCalculationSource;
    Cub: ICubeModel;
    sel: ICubeSelectionControl;
    param: IMetabaseObjectParam;
    dim: IDimensionModel;
    Des: IMetabaseObjectDescriptor;
    CrInf: IMetabaseObjectCreateInfo;
    objContrl: IMetabaseObjectControl;
    Params: IMetabaseObjectParams;
    DictParam: IMetabaseObjectDescriptor;
Begin
    Mb := MetabaseClass.Active;
    CrInf := Mb.CreateCreateInfo;
    CrInf.ClassId := MetabaseObjectClass.KE_CLASS_MDCALCULATION;
    CrInf.Name := "MDCALC";
    CrInf.Id := "MDCALC";
    CrInf.Parent := Mb.Root;
    CrInf.Permanent := True;
    Des := Mb.CreateObject(CrInf);
    dMd := Des.Edit;
    MDcalc := dMd As IMDCalculation;
// Determine database
    MDcalc.Database := Mb.ItemById("DB").Bind As IDatabase;
    Destination := MDcalc.Destination;
// Determine destination cube
    Cub := Mb.ItemById("CUBE_DEST").Bind As ICubeModel;
    Destination.SetCube(Cub);
// Determine source cube
    Cub := Mb.ItemById("CUBE_SOUR").Bind As ICubeModel;
    source := MDcalc.Sources.AddCube(Cub);
// Create a formulas table
    FormulasTable := MDcalc.FormulasTable;
    TableForFormulas := FormulasTable.Create;
    (TableForFormulas As IMetabaseObject).Save;
    FormulasTable.Attach(TableForFormulas);
// Create a parameter for multidimensional calculation
    Params := (dMd As IMetabaseObject).Params;
    param := Params.Add;
    param.Id := "PARAM";
    param.DataType := DbDataType.Integer;
// Set control of nested objects parameters
    DictParam := Mb.ItemById("PARAM_DICT");
    objContrl := Params.ControlInfo.FindByKey(DictParam.Key);
    objContrl.Item(0).Expression.AsString := ":PARAM";
// Set parameters control
    dim := DictParam.Bind As IDimensionModel;
    sel := MDcalc.SelectionControl;
    sel.Item(1).ControllingDim := dim;
    sel.Item(1).Expression.AsString := "FIRST.ID";
    sel.Item(1).SelectionStrategy := CubeSelectionControlStrategy.SelectFirst;
// Save calculation
    (dMd As IMetabaseObject).Save;
End Sub UserProc;

After executing the example a multidimensional calculation on DB server with the MDCALC identifier is created in the repository root. The CUBE_SOUR cube serves as a source cube, the CUBE_DEST cube serves as a destination cube. In multidimensional calculation the parameter, which influences parameter of destination cube dictionary, is created. A controlling dimension will be determined for the source cube. After rebuilding in the dependent dictionary the selection of the first element will be set.

See also:

Examples | IMDCalculation