ReadFormulas(
Key: IMDCalculationFormulaElementKey;
[Formulas: IMDCalculationFormulas = Null];
[Options: Integer = 0]): IMDCalculationFormulas;
Key. Unique key of the element, by which formulas must be read.
Formulas. The parameter that determines the collection, to which formulas are read by the specified element. If this parameter is not specified, a new collection of formulas is created.
Options. Optional parameter that is reserved for future.
The ReadFormulas method reads formulas based on the specified element.
Executing the example requires that the repository contains multidimensional calculation on database server with the MDCalc_1 identifier. Time dependency is enabled for formulas.
Sub UserProc;
Var
MB: IMetabase;
MDInst: IMDCalculationInstance;
Source: IMDCalculationSourceInstance;
Dest: IMDCalculationDestinationInstance;
Slices: IMDCalculationSlicesInstance;
Formulas: IMDCalculationFormulas;
Formula: IMDCalculationFormula;
FormulaExpression: IMDCalculationFormulaExpression;
SourceCoord, DestCoord: 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;
DestCoord := Dest.NewCoord;
Slices := Dest.Slices;
For i := 0 To Slices.Count - 1 Do
DestCoord.Item(i) := 0;
End For;
ElementKey := Dest.CoordToKey(DestCoord);
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(2025, 01, 01), DateTime.ComposeDay(2026, 01, 01));
// Set element from source as an operand
Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.Element);
SourceCoord := Source.NewCoord;
For i := 0 To Slices.Count - 1 Do
SourceCoord.Item(i) := 0;
End For;
SourceElKey := Source.CoordToKey(SourceCoord);
SourceElKey.FactIndex := 0;
CoordOperand := Operand As IMDCalculationFormulaElement;
CoordOperand.Key := SourceElKey;
FormulaExpression.InsertItem(Operand);
// Set the "*" symbol as an operand
Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.BinaryOperation);
BinaryOperand := Operand As IMDCalculationFormulaBinaryOperation;
BinaryOperand.BinaryOperation := MDCalculationFormulaBinaryOperation.Mul;
FormulaExpression.InsertItem(Operand);
// Set the "3.14" constant 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 UserProc;
After executing the example a formula is added for the specified data consumer element. The operation period is set for the formula. Operation periods of other formulas are adjusted according to this one.
See also: