Sum(Index: Integer): MDCalculationFormulaElementSum;
Index. Index of the dimension, by which summation is executed.
The Sum property determines a summation method. Summation parameters must be set up by dimension to use summation.
Executing the example requires that the repository contains multidimensional calculation on DB server with the MDCalc_1 identifier. There are two dimensions in the data source and data consumer: 1) Calendar dimension - fixed; 2) Dimension based on the table dictionary - summation parameters are set up for this dimension.
Sub Main;
Var
MB: IMetabase;
MDInst: IMDCalculationInstance;
Formulas: IMDCalculationFormulas;
Formula: IMDCalculationFormula;
FormulaExpression: IMDCalculationFormulaExpression;
Source: IMDCalculationSourceInstance;
Dest: IMDCalculationDestinationInstance;
Slices: IMDCalculationSlicesInstance;
Operand: IMDCalculationFormulaOperand;
DestCoo, SourceCoo: IMatrixCoord;
ElementKey, SourceElKey: IMDCalculationFormulaElementKey;
CoordOperand: IMDCalculationFormulaElement;
Begin
MB := MetabaseClass.Active;
MDInst := MB.ItemById("MDCALC_1").Open(Null) As IMDCalculationInstance;
Formulas := MDInst.CreateFormulas;
Formula := Formulas.Add;
FormulaExpression := Formula.Expression;
Source := MDInst.Sources.Item(0);
Slices := Source.Slices;
//Assign as an operand - coordinate in the source
Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.Element);
SourceCoo := Source.NewCoord;
SourceCoo.Item(0) := 1;
SourceElKey := Source.CoordToKey(SourceCoo);
SourceElKey.FactIndex := 0;
CoordOperand := Operand As IMDCalculationFormulaElement;
CoordOperand.Key := SourceElKey;
//Summation of child elements
CoordOperand.Sum(0) := MDCalculationFormulaElementSum.Sum;
FormulaExpression.InsertItem(Operand);
//Coordinate, by which formulas are written into the consumer
Dest := MDInst.Destination;
DestCoo := Dest.NewCoord;
Slices := Dest.Slices;
DestCoo.Item(0) := 0;
ElementKey := Dest.CoordToKey(DestCoo);
ElementKey.FactIndex := 0;
MDInst.WriteFormulas(ElementKey, Formulas);
End Sub Main;
After executing the example the formula is set for the first data consumer element. Value by coordinate in the data consumer is calculated as a sum of values of child elements of the first element in the data source.
See also: