IMDCalculationFormulaElement.Sum

Syntax

Sum(Index: Integer): MDCalculationFormulaElementSum;

Parameters

Index. Index of the dimension, by which summation is executed.

Description

The Sum property determines a summation method.

Comments

Summation parameters must be set up by dimension to use summation.

Example

Executing the example requires that the repository contains multidimensional calculation on database 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 UserProc;
Var
    MB: IMetabase;
    MDInst: IMDCalculationInstance;
    Formulas: IMDCalculationFormulas;
    Formula: IMDCalculationFormula;
    FormulaExpression: IMDCalculationFormulaExpression;
    Source: IMDCalculationSourceInstance;
    Dest: IMDCalculationDestinationInstance;
    Slices: IMDCalculationSlicesInstance;
    Operand: IMDCalculationFormulaOperand;
    DestCoord, SourceCoord: IMatrixCoord;
    ElementKey, SourceElKey: IMDCalculationFormulaElementKey;
    CoordOperand: IMDCalculationFormulaElement;
Begin
    MB := MetabaseClass.Active;
    MDInst := MB.ItemById("MDCALC_1").Open(NullAs IMDCalculationInstance;
    Formulas := MDInst.CreateFormulas;
    Formula := Formulas.Add;
    FormulaExpression := Formula.Expression;
    Source := MDInst.Sources.Item(0);
    Slices := Source.Slices;
    // Set the coordinate in the source as an operand
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.Element);
    SourceCoord := Source.NewCoord;
    SourceCoord.Item(0) := 1;
    SourceElKey := Source.CoordToKey(SourceCoord);
    SourceElKey.FactIndex := 0;
    CoordOperand := Operand As IMDCalculationFormulaElement;
    CoordOperand.Key := SourceElKey;
    // Summate child elements
    CoordOperand.Sum(0) := MDCalculationFormulaElementSum.Sum;
    FormulaExpression.InsertItem(Operand);
    // Coordinate, by which formula is written to data consumer
    Dest := MDInst.Destination;
    DestCoord := Dest.NewCoord;
    Slices := Dest.Slices;
    DestCoord.Item(0) := 0;
    ElementKey := Dest.CoordToKey(DestCoord);
    ElementKey.FactIndex := 0;
    MDInst.WriteFormulas(ElementKey, Formulas);
End Sub UserProc;

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:

IMDCalculationFormulaElement