ParamAttributes: IMsModelParamAttributes;
The ParamAttributes property returns parameter and chain of attributes.
To set compared attribute, use the IMsDimIteratorAdvancedFilterCondition.Attribute property.
To set comparison operator, use the IMsDimIteratorAdvancedFilterCondition.Operator_ property. Take into account features of working with the following operators:
MsAdvancedFilterConditionOperator.Between. A two-element array must be specified as a parameter value.
MsAdvancedFilterConditionOperator.In. An array of element must be specified as a parameter value.
To set compared value directly, use the IMsDimIteratorAdvancedFilterCondition.Value.
Executing the example requires that repository contains modeling container with the MS_STAT identifier containing metamodel with the METAMODEL_MULTIDIMITERATOR identifier. Data source for the container is time series database containing time series attributes with the CITY and INDICATOR identifiers. These attributes should be links to the dictionary. Dictionary to which the CITY attribute refers must contain the parameter of logical type with the ISCAPITAL identifier.
The container must also contain modeling problem with the PROBLEM_MULTIDIMITERATOR identifier calculating the METAMODEL_MULTIDIMITERATOR metamodel and the model with the MODEL_MULTIDIMITERATOR identifier.
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: IRubricator;
Attributes: IMetaAttributes;
CDict, IDict: IMetabaseObjectDescriptor;
Chain: IMsCalculationChainEntries;
mParams: IMsModelParams;
CParam, IParam, FParam: IMsModelParam;
iterator: IMsCalculationChainMultiDimIterator;
dimInstC, dimInstI: IDimInstance;
IterDims: IMsDimIteratorDimensions;
CIterDim, IIterDim: IMsDimIteratorDimension;
Filter: IMsDimIteratorFilter;
dimSelC, dimSelI: IDimSelection;
CAdvFilter: IMsDimIteratorAdvancedFilter;
CAdvFilterCond: IMsDimIteratorAdvancedFilterCondition;
model: IMsModel;
Problem: IMsProblem;
CalcSett: IMsProblemCalculationSettings;
Calc: IMsProblemCalculation;
i: Integer;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modeling 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;
IDict := Attributes.FindById("INDICATOR").ValuesObject;
// Get and clear metamodel parameters
mParams := pMetaModel.Params;
mParams.Clear;
// Add a parameter based on dictionary of the CITY attribute
CParam := mParams.Add;
CParam.DataType := DbDataType.integer;
CParam.Hidden := True;
CParam.Id := "CITY";
CParam.Name := "City";
CParam.LinkedObject := CDict;
CParam.ParamType := TsParamType.Selection;
dimInstC := CDict.Open(Null) As IDimInstance;
dimSelC := dimInstC.CreateSelection;
dimSelC.SelectAll;
CParam.DefaultValue := dimSelC;
// Add an attribute to use in advanced filter
FParam := mParams.Add;
FParam.Hidden := True;
FParam.DataType := DbDataType.Boolean;
FParam.Id := "CAPITAL";
FParam.Name := "Capital";
FParam.ParamType := TsParamType.Simple;
FParam.DefaultValue := True;
// Add a parameter based on dictionary of the INDICATOR attribute
IParam := mParams.Add;
IParam.DataType := DbDataType.Integer;
IParam.Hidden := True;
IParam.Id := "INDICATOR";
IParam.Name := "Factor";
IParam.LinkedObject := IDict;
IParam.ParamType := TsParamType.Selection;
dimInstI := IDict.Open(Null) As IDimInstance;
dimSelI := dimInstI.CreateSelection;
dimSelI.SelectAll;
// 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 iterated dimensions
IterDims := Iterator.Dimensions;
// Add a dimension based on dictionary of the CITY attribute
CIterDim := IterDims.Add(dimInstC);
// Set dimension parameter
CIterDim.Parameter := CParam;
// Set filter of elements
Filter := CIterDim.Filter;
Filter.Selection := dimSelC;
// Get advanced filter
CAdvFilter := Filter.AdvancedFilter;
// Add an advanced filtering condition
CAdvFilterCond := CAdvFilter.Add;
// Set filtered attribute
CAdvFilterCond.Attribute := dimInstC.Attributes.FindById("ISCAPITAL").Attribute;
// Set comparison operator
CAdvFilterCond.Operator_ := MsAdvancedFilterConditionOperator.Equal;
// Set required attribute value as parameter
CAdvFilterCond.ParamAttributes.Parameter := FParam;
// Determine that this is a reverse condition
CAdvFilterCond.Inversed := True;
// Ignore empty values of dimension attribute
CAdvFilterCond.IgnoreEmptyAttributes := True;
// Do not take into account empty values of parameter
CAdvFilterCond.IgnoreEmptyValues := True;
// Display name of filtered dimension
Debug.WriteLine("Dimension containing advanced filter: " + (CAdvFilterCond.Owner As IMsDimIteratorFilter).Owner.Name);
// Add a dimension based on dictionary of the INDICATOR attribute
IIterDim := IterDims.Add(dimInstI);
// Set dimension parameter
IIterDim.Parameter := IParam;
// Set filter of elements
Filter := IIterDim.Filter;
Filter.Selection := dimSelI;
// Add model to multidimensional iterator
model := mb.ItemByIdNamespace("MODEL_MULTIDIMITERATOR", MsKey).Bind As IMsModel;
Iterator.Contents.AddModel(model);
// Save changes in metamodel
(pMetaModel As IMetabaseObject).Save;
// Check advanced filter. Display dictionary elements in the console window,
// that correspond to filter
Problem := mb.ItemByIdNamespace("PROBLEM_MULTIDIMITERATOR", MsKey).Edit As IMsProblem;
Calc := Problem.Calculate(Problem.CreateCalculationSettings);
Debug.WriteLine("Dictionary elements corresponding to filter: ");
Debug.Indent;
For i := 0 To dimSelC.SelectedCount - 1 Do
If CAdvFilter.Test(dimSelC.Element(i), Calc) Then
Debug.WriteLine(dimSelC.Dimension.Elements.Name(dimSelC.Element(i)));
End If;
End For;
End Sub UserProc;
After executing the example, a multidimensional iterator and the CAPITAL logical parameter are created in the metamodel. A model is added to the iterator. An advanced filter is added for the dimension based on a dictionary of the CITY attribute: only the elements, which value of the ISCAPITAL attribute is reverse to the CAPITAL parameter value added to the metamodel. These elements are displayed in the console window.
See also: