IMDCalculationFormulaFunctionCall.FunctionCall

Syntax

FunctionCall: MDCalculationFormulaFunctionCall;

Description

The FunctionCall property determines a form of special function used in a formula.

Comments

The type of the function in use determines the following list of operands. Syntax of functions is given in the Special Functions section.

Example

Executing the example requires that the repository contains multidimensional calculation on DB server with the MDCalc_1 identifier.

Sub UserProc;
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;
    ConstOperand: IMDCalculationFormulaConstantValue;
    BinaryOperand: IMDCalculationFormulaBinaryOperation;
    FuncCallOperand: IMDCalculationFormulaFunctionCall;
    DelimiterOperand: IMDCalculationFormulaDelimiter;
    DatePeriodOperand: IMDCalculationFormulaDatePeriod;
    i: Integer;
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;
    //Specify the coordinate in the source as the operand
    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);
    //Specify the "*" symbol as an operand
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.BinaryOperation);
    BinaryOperand := Operand As IMDCalculationFormulaBinaryOperation;
    BinaryOperand.BinaryOperation := MDCalculationFormulaBinaryOperation.Mul;
    FormulaExpression.InsertItem(Operand);
    //Specify the "3.14" constant as an operand
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.ConstantValue);
    ConstOperand := Operand As IMDCalculationFormulaConstantValue;
    ConstOperand.ConstantValue := 3.14;
    FormulaExpression.InsertItem(Operand);
    //Coordinate, by which formula is recorded to data consumer
    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;
    //Record formula by the first coordinate
    MDInst.WriteFormulas(ElementKey, Formulas);
    //Then add Shift function to the formula and record by the second coordinate
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.FunctionCall);
    FuncCallOperand := Operand As IMDCalculationFormulaFunctionCall;
    FuncCallOperand.FunctionCall := MDCalculationFormulaFunctionCall.Shift;
    //Insert the Shift function in the first position
    FormulaExpression.InsertItem(Operand, 0);
    //Specify the "," delimiter as an operand
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.Delimiter);
    DelimiterOperand := Operand As IMDCalculationFormulaDelimiter;
    DelimiterOperand.Delimiter := MDCalculationFormulaDelimiter.Comma;
    //Insert "," to the third position
    FormulaExpression.InsertItem(Operand, 2);
    //Insert "Day"
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.DatePeriod);
    DatePeriodOperand := Operand As IMDCalculationFormulaDatePeriod;
    DatePeriodOperand.DatePeriod := MDCalculationFormulaDatePeriod.Day;
    FormulaExpression.InsertItem(Operand, 3);
    //Insert ","
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.Delimiter);
    DelimiterOperand := Operand As IMDCalculationFormulaDelimiter;
    DelimiterOperand.Delimiter := MDCalculationFormulaDelimiter.Comma;
    FormulaExpression.InsertItem(Operand, 4);
    //Insert "1" to the last position
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.ConstantValue);
    ConstOperand := Operand As IMDCalculationFormulaConstantValue;
    ConstOperand.ConstantValue := 1;
    FormulaExpression.InsertItem(Operand, 5);
    //Insert ")" to the last position
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.Delimiter);
    DelimiterOperand := Operand As IMDCalculationFormulaDelimiter;
    DelimiterOperand.Delimiter := MDCalculationFormulaDelimiter.RightPar;
    FormulaExpression.InsertItem(Operand, 6);
    Dest := MDInst.Destination;
    DestCoo := Dest.NewCoord;
    Slices := Dest.Slices;
    For i := 0 To Slices.Count - 1 Do
        DestCoo.Item(i) := 1;
    End For;
    ElementKey := Dest.CoordToKey(DestCoo);
    ElementKey.FactIndex := 0;
    //Record formula by the second coordinate
    MDInst.WriteFormulas(ElementKey, Formulas);
End Sub UserProc;

After executing the example the formula is set for the specified data consumer element. The value by coordinate in the data consumer is calculated by the formula: value by coordinate in the data source is multiplied by 3.14. Value by the second coordinate in the data consumer is calculated by the same formula, but value of coordinate in the data source is taken with one day shift according to the calendar dimension (The Shift function is used to get value).

See also:

IMDCalculationFormulaFunctionCall