Expression: IMDCalculationFormulaExpression;
The Expression property returns the expression obtained after parsing the Text string.
Executing the example requires that the repository contains multidimensional calculation on DB server with the MDCalc_1 identifier.
Sub Main;
Var
MB: IMetabase;
MDInst: IMDCalculationInstance;
Source: IMDCalculationSourceInstance;
Parser: IMDCalculationExpressionParser;
SourceCoord, DestCoord: IMatrixCoord;
SourceKey, DestKey: IMDCalculationFormulaElementKey;
Dest: IMDCalculationDestinationInstance;
Formulas: IMDCalculationFormulas;
Formula: IMDCalculationFormula;
i: Integer;
Begin
MB := MetabaseClass.Active;
MDInst := MB.ItemById("MDCalc_1").Open(Null) As IMDCalculationInstance;
Source := MDInst.Sources.Item(0);
Parser := MDInst.CreateParser;
SourceCoord := Source.NewCoord;
For i := 0 To SourceCoord.Count - 1 Do
SourceCoord.Item(i) := 0;
End For;
SourceKey := Source.CoordToKey(SourceCoord);
Parser.TermKey("Term") := SourceKey;
Parser.Text := "Shift(Term, Year, 1)*3.14";
Parser.Parse;
Dest := MDInst.Destination;
DestCoord := Dest.NewCoord;
For i := 0 To SourceCoord.Count - 1 Do
DestCoord.Item(i) := 0;
End For;
DestKey := Dest.CoordToKey(DestCoord);
Formulas := MDInst.CreateFormulas;
Formula := Formulas.Add;
Parser.Expression.CopyTo(Formula.Expression);
MDInst.WriteFormulas(DestKey, Formulas);
End Sub Main;
After executing the example a new formula for the specified data consumer element is created. The formula is obtained through text string parse. Instead of a term the data source specified element is substituted into the expression.
See also: