IMDCalculationFormulaUnaryOperation.UnaryOperation

Syntax

UnaryOperation: MDCalculationFormulaUnaryOperation;

Description

The UnaryOperation property determines a type of unary operation used as a formula operand.

Example

Executing the example requires that the repository contains multidimensional calculation on database 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;
    DestCoord, SourceCoord: IMatrixCoord;
    ElementKey, SourceElKey: IMDCalculationFormulaElementKey;
    UnaryOperand: IMDCalculationFormulaUnaryOperation;
    CoordOperand: IMDCalculationFormulaElement;
    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;
    // Set the - sign as an operand
    Operand := FormulaExpression.CreateItem(MDCalculationFormulaOperandKind.UnaryOperation);
    UnaryOperand := Operand As IMDCalculationFormulaUnaryOperation;
    UnaryOperand.UnaryOperation := MDCalculationFormulaUnaryOperation.Minus;
    FormulaExpression.InsertItem(Operand);
    // Set the coordinate in the 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);
    // Coordinate, by which formula is written to data consumer
    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;
    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: 0 - the value by coordinate in the data source.

See also:

IMDCalculationFormulaUnaryOperation