AttributeFormulasList: IMsAttributesFormulasList;
The AttributeFormulasList property returns the collection of methods for calculating additional attributes by formulas.
This property is used if the model is included in the modeling container of the time series database. Collection formulas are used to calculate additional attributes for factors. Each element of the collection is implemented by the IMsFormulaTransform interface and allows to set up parameters of attribute calculation.
Executing the example requires that the repository contains a time series database with the OBJ_RUBRICATOR identifier. The database contains an additional string attribute of factors with the COMM identifier used to store a comment to factors. Modeling container of the database contains a model with the MODEL identifier. Also, before executing the procedure it is necessary to add links to the Ms, Cubes, Rds, Metabase, Dimentions, System system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
Rubr: IRubricator;
Model: IMsModel;
FormulasList: IMsAttributesFormulasList;
AttrTranfsorm: IMsFormulaTransform;
ModelTransform: IMsFormulaTransform;
ModelOutputs: IMsFormulaTransformVariables;
OutputVar: IMsFormulaTransformVariable;
AttrOutputs: IMsFormulaTransformVariables;
TransVar: IMsFormulaTransformVariable;
OutputSlices: IMsFormulaTransformSlices;
SelectionSet: IDimSelectionSet;
Slice: IMsFormulaTransformSlice;
AttrValueList: IMsMetaAttributeValueList;
RubrMetaAttrs: IMetaAttributes;
RubrAttr: IMetaAttribute;
AttrVal: IMsMetaAttributeValue;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
Determ: IMsDeterministicTransform;
Expr: IExpression;
DetermOperands: IMsFormulaTermList;
tInfo: IMsFormulaTermInfo;
Begin
Mb := MetabaseClass.Active;
Rubr := Mb.ItemById("OBJ_RUBRICATOR").Bind As IRubricator;
Model := Mb.ItemByIdNamespace("MODEL", Rubr.ModelSpace.Key).Edit As IMsModel;
ModelTransform := Model.Transform;
ModelOutputs := ModelTransform.Outputs;
OutputVar := ModelOutputs.Item(0);
// Receive the list of methods by which the additional attributes are calculated.
FormulasList := Model.AttributeFormulasList;
FormulasList.Clear;
// Add the new calculation method of additional attribute and assign its parameters
AttrTranfsorm := FormulasList.Add;
AttrOutputs := AttrTranfsorm.Outputs;
TransVar := AttrOutputs.Add(OutputVar.VariableStub);
TransVar.AttributeId := "COMM";
OutputSlices := OutputVar.Slices;
SelectionSet := OutputSlices.Item(0).Selection;
Slice := TransVar.Slices.Add(SelectionSet);
AttrValueList := Slice.MetaAttributeValueList;
AttrValueList.Clear;
RubrMetaAttrs := Rubr.Facts.Attributes;
RubrAttr := RubrMetaAttrs.FindById("COMM");
AttrVal := AttrValueList.Add(RubrAttr);
AttrVal.Kind := MsMetaAttributeValueType.Unspecified;
Selector := AttrTranfsorm.CreateSelector;
Selector.Slice := Slice;
Formula := AttrTranfsorm.Transform(Selector);
Formula.Kind := MsFormulaKind.Deterministic;
Determ := Formula.Method As IMsDeterministicTransform;
DetermOperands := Determ.Operands;
DetermOperands.Clear;
tInfo := DetermOperands.Add(Slice).TermInfo;
Expr := Determ.Expression;
Expr.AsString := "iif(" + tInfo.TermInnerText + "<>""""," + tInfo.TermInnerText + ",""Comment was absent"")";
If Not (Expr.Valid)
Then Debug.WriteLine(expr.ErrorInfo.ErrorMessage);
Else (Model As IMetabaseObject).Save;
End If;
End Sub UserProc;
After executing the example, on calculating the model, attribute of the COMM factors for output variable is calculated as follows:
If the COMM attribute is set, its value is not changed.
If the COMM attribute is not set, its value is changed to Comment Is Absent.
See also: