IMDCalculationFormula.Expression

Syntax

Expression: IMDCalculationFormulaExpression;

Description

The Expression property returns the formula expression used for calculation.

Example

Executing the example requires that the repository contains multidimensional calculation on DB server with the MDCalc_1 identifier. Time dependency is enabled for formulas.

Sub Main;

Var

MB: IMetabase;

MDInst: IMDCalculationInstance;

Source: IMDCalculationSourceInstance;

Dest: IMDCalculationDestinationInstance;

Slices: IMDCalculationSlicesInstance;

Formulas: IMDCalculationFormulas;

Formula: IMDCalculationFormula;

FormulaExpression: IMDCalculationFormulaExpression;

DestCoo, SourceCoo: IMatrixCoord;

SourceElKey, ElementKey: IMDCalculationFormulaElementKey;

Operand: IMDCalculationFormulaOperand;

CoordOperand: IMDCalculationFormulaElement;

BinaryOperand: IMDCalculationFormulaBinaryOperation;

ConstOperand: IMDCalculationFormulaConstantValue;

i: Integer;

Begin

MB := MetabaseClass.Active;

MDInst := MB.ItemById("MDCalc_1").Open(Null) As IMDCalculationInstance;

Dest := MDInst.Destination;

DestCoo := Dest.NewCoord;

Slices := Dest.Slices;

For i := 0 To Slices.Count - 1 Do

DestCoo.Item(i) := 0;

End For;

ElementKey := Dest.CoordToKey(DestCoo);

ElementKey.FactIndex := 0;

Source := MDInst.Sources.Item(0);

Slices := Source.Slices;

Formulas := MDInst.ReadFormulas(ElementKey);

Formula := Formulas.Add;

FormulaExpression := Formula.Expression;

Formula.ChangePeriod(DateTime.ComposeDay(2007, 01, 01), DateTime.ComposeDay(2007, 01, 01));

//Assign as an operand - element from the source

Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.Element);

SourceCoo := Source.NewCoord;

For i := 0 To Slices.Count - 1 Do

SourceCoo.Item(i) := 0;

End For;

SourceElKey := Source.CoordToKey(SourceCoo);

SourceElKey.FactIndex := 0;

CoordOperand := Operand As IMDCalculationFormulaElement;

CoordOperand.Key := SourceElKey;

FormulaExpression.InsertItem(Operand);

//Assign symbol * as an operand

Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.BinaryOperation);

BinaryOperand := Operand As IMDCalculationFormulaBinaryOperation;

BinaryOperand.BinaryOperation := MDCalculationFormulaBinaryOperation.Mul;

FormulaExpression.InsertItem(Operand);

//Assign constant 3.14 as an operand

Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.ConstantValue);

ConstOperand := Operand As IMDCalculationFormulaConstantValue;

ConstOperand.ConstantValue := 3.14;

FormulaExpression.InsertItem(Operand);

MDInst.WriteFormulas(ElementKey, Formulas);

End Sub Main;

After executing the example the formula is added for the specified data consumer element. The actual period is set for the formula. Actual periods of other formulas are adjusted according to this one.

See also:

IMDCalculationFormula