IMsDimIteratorFilter.ElementGroup

Syntax

ElementGroup: IDimElementGroup;

Description

The ElementGroup property determines a group of iterated elements.

Comments

To directly pass selection, and not as a parameter, use the IMsDimIteratorFilter.Selection property.

Example

Executing the example requires that the repository contains a modeling container with the MS_STAT identifier containing 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. The dictionary, to which the CITY attribute refers, should contain a group of elements.

The repository should also contain a time series database with the TSDB identifier, which is not a data source for the M_STAT 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, Dimensions, Metabase, Ms, Rds system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    MsKey: Integer;
    pMetaModel: IMsMetaModel;
    Ms: IMsModelSpace;
    DS, DSLinked: IRubricator;
    Attributes: IMetaAttributes;
    CDict, IDict, Child: IMetabaseObjectDescriptor;
    i: Integer;
    CGroup: IDimElementGroup;
    Chain: IMsCalculationChainEntries;
    iterator: IMsCalculationChainMultiDimIterator;
    IteratorOpt: IMsDimIterateByDataOptions;
    IterStubs: IMsDimIterateByDataStubs;
    dimInstC, dimInstI, dimLinked: IDimInstance;
    IterDims: IMsDimIteratorDimensions;
    CIterDim, IIterDim: IMsDimIteratorDimension;
    Filter: IMsDimIteratorFilter;
    IterStub: IMsDimIterateByDataStub;
    IDimLink: IMsDimIteratorLink;
    model: IMsModel;
    Trans: IMsFormulaTransform;
    TransVar: IMsFormulaTransformVariable;
    slice: IMsFormulaTransformSlice;
    SelectionFact: IDimSelectionSetFactory;
    SelSet: IDimSelectionSet;
    Selector: IMsFormulaTransformSelector;
    Formula: IMsFormula;
    Determ: IMsDeterministicTransform;
    TermInfo: IMsFormulaTermInfo;
    Expr: IExpression;
Begin
    // Get current repository
    mb := MetabaseClass.Active;
    // Get modelling container key
    MsKey := mb.GetObjectKeyById("MS_STAT");
    // 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 factor attributes
    Attributes := DS.Facts.Attributes;
    // Get dictionaries used as a base for the CITY and INDICATOR attributes
    CDict := Attributes.FindById("CITY").ValuesObject;
    dimInstC := CDict.Open(NullAs IDimInstance;
    IDict := Attributes.FindById("INDICATOR").ValuesObject;
    dimInstI := IDict.Open(NullAs IDimInstance;
    // Get group of elements from dictionary, on which the CITY attribute is based
    For i := 0 To CDict.Children.Count - 1 Do
        Child := CDict.Children.Item(i);
        If Child.ClassId = 1029 Then
            CGroup := Child.Bind As IDimElementGroup;
            Break;
        End If;
    End For;
    // Get and clear metamodel calculation chain
    Chain := pMetaModel.CalculationChain;
    Chain.Clear;
    // 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);
    // Set data source for iterated dimension
    CIterDim.Stubs.Add(DS As IVariableStub);
    // Set parametric element filter
    Filter := CIterDim.Filter;
    Filter.ElementGroup := CGroup;
    Debug.WriteLine("Filtering dimension: " + Filter.Owner.Name);
    // Add a dimension based on dictionary of the INDICATOR attribute
    IIterDim := IterDims.Add(dimInstI);
    // Set data source for iterated dimension
    IIterDim.Stubs.Add(DS As IVariableStub);
    // 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.Open(NullAs IDimInstance;
    // Add a dictionary as a linked dimension
    IDimLink := IIterDim.Links.Add(dimLinked);
    // Specify source attribute and consumer attribute
    IDimLink.SourceAttribute := dimInstI.Attributes.FindById("NAME").Attribute;
    IDimLink.DestinationAttribute := dimLinked.Attributes.FindById("NAME").Attribute;
    // Specify data source of linked dimension
    IDimLink.Dimension.Stubs.Add(DSLinked As IVariableStub);
    // Get data source, using which iterations will be executed
    // and display its name in the console window      
    IterStub := IterStubs.Item(0);
    Debug.WriteLine("Data source used for iteration execution: " + IterStub.Stub.Name);
    // Create a model inside multidimensional iterator
    model := Iterator.Contents.AddExclusiveModel.Model;
    // Set up model
    Trans := model.Transform;
    // Add an output variable
    TransVar := Trans.Outputs.Add(DS As IVariableStub);
    Slice := TransVar.Slices.Add(Null);
    SelectionFact := New DimSelectionSetFactory.Create;
    SelSet := SelectionFact.CreateDimSelectionSet;
    SelSet.Add(dimInstC);
    SelSet.Add(dimInstI);
    SelSet.Item(0).SelectElement(1False);
    SelSet.Item(1).SelectElement(1False);
    Slice.Selection := SelSet;
    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
    TransVar := Trans.Inputs.Add(DS As IVariableStub);
    Slice := TransVar.Slices.Add(Null);
    Slice.Selection := SelSet;
    TermInfo := Trans.CreateTermInfo;
    TermInfo.Slice := Slice;
    // Set expression to calculate a model
    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, 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:

IMsDimIteratorFilter