AbsI(Input: Variant): Variant;
Input. Variable.
The AbsI method returns absolute value (modulus) of selected variable points if this variable contains only integer values.
Use the IModelling.Abs method to calculate points module of the variable containing not only integer values.
Executing the example requires that the repository contains a modeling container with the MS identifier. This container includes a model with the MODEL_D identifier that is calculated by the determinate equation method and contains at least one input variable.
Add links to the Metabase and Ms system assemblies.
Sub UserAbsI;
Var
Mb: IMetabase;
ModelSpace, ModelObj: IMetabaseObject;
Transf: IMsFormulaTransform;
Formula: IMsFormula;
Model: IMsModel;
Determ: IMsDeterministicTransform;
TransVar: IMsFormulaTransformVariable;
Slice: IMsFormulaTransformSlice;
TermInfo: IMsFormulaTermInfo;
Expr: IExpression;
Begin
Mb := MetabaseClass.Active;
ModelSpace := Mb.ItemById("MS").Bind;
ModelObj := Mb.ItemByIdNamespace("MODEL_D", ModelSpace.Key).Edit;
Model := ModelObj As IMsModel;
Transf := Model.Transform;
Formula := Transf.FormulaItem(0);
Determ := Formula.Method As IMsDeterministicTransform;
TransVar := Transf.Inputs.Item(0);
Slice := TransVar.Slices.Item(0);
TermInfo := Transf.CreateTermInfo;
TermInfo.Slice := Slice;
Expr := Determ.Expression;
Expr.References := "Ms";
Expr.AsString := "AbsI(" + TermInfo.TermInnerText + ")";
If Expr.Valid
Then ModelObj.Save;
Else Debug.WriteLine(Model is not saved: error in formula);
End If;
End Sub UserAbsI;
After executing the example the model will calculate the absolute value (modulus) of points of the first input variable if it contains only integer values.
Expression 1:
AbsI({Brazil|BCA})
Result: absolute value is calculated for each observation of the Brazil|BCA time series. An error occurs if the factor contains real values.
Use: it can be used in formulas of cross functional expression editor in any platform tool where it is available.
Expression 2:
AbsI(X1)
Result: absolute value is calculated for each point of the X1 factor.
Use: it can be used in model formulas of modeling container.
Expression 3:
AbsI(-7)
Result: 7.
Application: it can be used in any expressions.
See also:
IModelling | Time Series Database: Calculator, Absolute Value | Modeling Container: Editing Regressor or Formula