IMsDimIteratorLinks.AddByDimModel

Syntax

AddByDimModel(DimModel: IDimensionModel): IMsDimIteratorLink;

Parameters

DimModel. Structure of added dimension.

Description

The AddByDimModel method adds linked dimension structure to the collection.

Comments

Work with dimension structure and not with dimension instance required in the IMsDimIteratorLinks.Add method allows for reducing the time of adding a collection dimension because the dimension does not open. Opening of dimensions with a number of elements may take longer time.

Example

Executing the example requires that the repository contains a modeling container with the MS_P identifier including a metamodel with the METAMODEL_MULTIDIMITERATOR identifier. A data source for the container is a time series database containing time series attributes with the CITY and INDICATOR identifiers. These attributes should be links to the dictionary. A dictionary, to which the CITY attribute refers, should contain a parameter with logical type with the ISCAPITAL identifier.

The repository should contain a time series database with the TSDB identifier, which is not a data source for the MS_P modeling container. This time series database should contain a time series attribute with the INDICATOR identifier. The attribute should be a link to the dictionary.

Add links to the Cubes, Dal, Dimensions, Metabase, Ms, Rds,Transform system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    MsKey: Integer;
    pMetaModel: IMsMetaModel;
    Ms: IMsModelSpace;
    DS, DSLinked: IRubricator;
    Attributes: IMetaAttributes;
    CDict, IDict: IMetabaseObjectDescriptor;
    Chain: IMsCalculationChainEntries;
    params: IMsModelParams;
    CParam, IParam: IMsModelParam;
    iterator: IMsCalculationChainMultiDimIterator;
    IteratorOpt: IMsDimIterateByDataOptions;
    IterStubs: IMsDimIterateByDataStubs;
    dimInstC, dimInstI: IDimInstance;
    dimLinked: IDimensionModel;
    IterDims: IMsDimIteratorDimensions;
    CIterDim, IIterDim: IMsDimIteratorDimension;
    Filter: IMsDimIteratorFilter;
    dimSelC, dimSelI: IDimSelection;
    IterStub: IMsDimIterateByDataStub;
    FilterDim: IMsDimIteratorFilteredDimension;
    IDimLink: IMsDimIteratorLink;
    model: IMsModel;
    Trans: IMsFormulaTransform;
    TransVar: IMsFormulaTransformVariable;
    slice: IMsFormulaTransformSlice;
    Selector: IMsFormulaTransformSelector;
    Formula: IMsFormula;
    Determ: IMsDeterministicTransform;
    TermInfo: IMsFormulaTermInfo;
    Expr: IExpression;
Begin
    // Get the current repository
    mb := MetabaseClass.Active;
    // Get modelling container key
    MsKey := mb.GetObjectKeyById("MS_P");
    // Get model
    pMetaModel := mb.ItemByIdNamespace("METAMODEL_MULTIDIMITERATOR", MsKey).Edit As IMsMetaModel;
    // Get modeling container
    Ms := mb.Item(MsKey).Bind As IMsModelSpace;
    // Get time series database,
    // which is a data source for modeling container
    DS := Ms.DefaultObject.Bind As IRubricator;
    // Get indicators attributes
    Attributes := DS.Facts.Attributes;


    // Get dictionaries used as a base for the CITY and INDICATOR attributes
    CDict := Attributes.FindById("CITY").ValuesObject;
    IDict := Attributes.FindById("INDICATOR").ValuesObject;
    // Get and clear metamodel calculation chain
    Chain := pMetaModel.CalculationChain;
    Chain.Clear;
    // Get and clear metamodel parameters
    params := pMetaModel.Params;
    params.Clear;


    // Add a parameter based on  dictionary of the CITY attribute
    CParam := params.Add;
    CParam.DataType := DbDataType.integer;
    CParam.DefaultValue := 1;
    CParam.Hidden := True;
    CParam.Id := "CITY";
    CParam.Name := "City";
    CParam.LinkedObject := CDict;
    CParam.ParamType := TsParamType.Selection;
    dimInstC := CDict.OpenWithParam("TRUE"As IDimInstance;
    dimSelC := dimInstC.CreateSelection;
    dimSelC.SelectElement(1False);
    CParam.DefaultValue := dimSelC;


    // Add a parameter based on dictionary of the INDICATOR attribute
    IParam := params.Add;
    IParam.DataType := DbDataType.Integer;
    IParam.DefaultValue := 1;
    IParam.Hidden := True;
    IParam.Id := "INDICATOR";
    IParam.Name := "Indicator";
    IParam.LinkedObject := IDict;
    IParam.ParamType := TsParamType.Selection;
    dimInstI := IDict.Open(NullAs IDimInstance;
    dimSelI := dimInstI.CreateSelection;
    dimSelI.SelectElement(1False);
    IParam.DefaultValue := dimSelI;


    // Add a multidimensional iterator to metamodel calculation chain
    iterator := Chain.AddMultiDimIterator("Multidimensional iterator");
    // Get iterator parameters by data
    IteratorOpt := Iterator.IterateByData;
    // Specify that it is active
    IteratorOpt.Active := True;


    // Set data source for iterator
    IterStubs := IteratorOpt.Stubs;
    IterStubs.Add(DS As IVariableStub);


    // Get iterated dimensions
    IterDims := Iterator.Dimensions;


    // Add a dimension based on dictionary of the CITY attribute
    CIterDim := IterDims.Add(dimInstC);
    // Specify that dimension is parametric
    CIterDim.Parameter := CParam;
    // Set data source for iterated dimension
    CIterDim.Stubs.Add(DS As IVariableStub);

    // Set element filter
    Filter := CIterDim.Filter;
    dimSelC.SelectAll;
    Filter.Selection := dimSelC;


    // Add a dimension based on dictionary of the INDICATOR attribute
    IIterDim := IterDims.Add(dimInstI);
    // Specify that dimension is parametric
    IIterDim.Parameter := IParam;
    // Set data source for iterated dimension
    IIterDim.Stubs.Add(DS As IVariableStub);
    // Set element filter
    Filter := IIterDim.Filter;
    dimSelI.SelectAll;
    Filter.Selection := dimSelI;


    // Get the TSDB time series database
    DSLinked := mb.ItemById("TSDB").Bind As IRubricator;
    // Get dictionary, on which the INDICATOR attribute is based
    Attributes := DSLinked.Facts.Attributes;
    dimLinked := Attributes.FindById("INDICATOR").ValuesObject.Bind As IDimensionModel;
    // Add a dictionary as a linked dimension
    IDimLink := IIterDim.Links.AddByDimModel(dimLinked);


    // Specify source attribute and consumer attribute
    IDimLink.SourceAttribute := dimSelI.Dimension.Attributes.FindById("NAME").Attribute;
    IDimLink.DestinationAttribute := dimLinked.Attributes.FindById("NAME");
    // Specify data source of linked dimension
    IDimLink.Dimension.Stubs.Add(DSLinked As IVariableStub);


    // Get data source, by which iterations will be executed
    // and display its name in the console window
    IterStub := IterStubs.Item(0);
    Debug.WriteLine("Data source, by which iteration is executed: " + IterStub.Stub.Name);


    // Add a filtering by the dimension, on which the CITY attribute is based
    FilterDim := IterStub.Dimension(dimInstC.InstanceModel);
    Debug.WriteLine("  Filtering dimension: " + FilterDim.Dimension.Name);
    FilterDim.Filter.Selection := dimSelC;


    // Specify parameter used for dimension opening
    FilterDim.DimOpenParam.Values := CDict.Bind.Params.CreateEmptyValues;
    FilterDim.DimOpenParam.Values.FindById("ISCAPITAL").Value := "TRUE";


    // Add a filtering by the dimension, on which the INDICATOR attribute is based
    FilterDim := IterStub.Dimension(dimInstI.InstanceModel);
    FilterDim.Filter.Selection := dimSelI;
    Debug.WriteLine("  Filtering dimension: " + FilterDim.Dimension.Name);


    // Create a model inside multidimensional iterator
    model := Iterator.Contents.AddExclusiveModel.Model;
    // Set up model
    Trans := model.Transform;


    // Add a modelling variable, which attributes are set by the parameters
    TransVar := Trans.Outputs.Add(DS As IVariableStub);
    Slice := TransVar.Slices.Add(Null);
    Slice.ParametrizedDimensions.Item(0).ParamAttributes.Parameter := IParam;
    Slice.ParametrizedDimensions.Item(1).ParamAttributes.Parameter := CParam;
    Selector := Trans.CreateSelector;
    Selector.Slice := Slice;


    // Set up model calculation method: determinate equation
    Formula := Trans.Transform(Selector);
    Formula.Kind := MsFormulaKind.Deterministic;
    Determ := Formula.Method As IMsDeterministicTransform;


    // Add an input variable, which attributes are set by the parameters
    TransVar := Trans.Inputs.Add(DS As IVariableStub);
    Slice := TransVar.Slices.Add(Null);
    Slice.ParametrizedDimensions.Item(0).ParamAttributes.Parameter := IParam;
    Slice.ParametrizedDimensions.Item(1).ParamAttributes.Parameter := CParam;
    TermInfo := Trans.CreateTermInfo;
    TermInfo.Slice := Slice;


    // Set expression for model calculation
    Expr := Determ.Expression;
    Expr.AsString := TermInfo.TermInnerText + "+1";
    If Expr.ErrorInfo <> Null Then
        debug.WriteLine(Expr.ErrorInfo.ErrorMessage);
        Return;
    End If;


    
// Save changes in model
    model.MetabaseObject.Save;
    
// Save changes in metamodel
    (pMetaModel As IMetabaseObject).Save;
End Sub UserProc;

After executing the example a multidimensional data iterator will be created in metamodel. The model calculated only by the dimension points containing data is created inside the iterator.

See also:

IMsDimIteratorLinks