Setting Up Calculated Facts in Standard Cube

On creating a standard cube, the facts are linked to the fields of data sources after their hierarchy is formed. If facts are not linked to the data source, the formulas of those facts, by which the values are calculated, can be specified later on. Those facts are called Calculated, and in the wizard their parameters are set up on the Calculated Facts tab. Calculated facts from the applied code are worked as follows:

Any mathematical expression or a macro, which is executed for each cube coordinate, can be used as a formula. Macro is used in the following format: <unit or form identifier>.<function name>.

Macros Formation for Calculated Facts

The function implemented in the global namespace of the unit or the form must be used as a macro for the calculated fact. The function may have different parameters. Other cube fact values can also be passed to the function through the parameters.

Example of functions for calculated facts:

Function CalculateFact: Variant;
Var
    Value: Variant;
Begin
    Value := ...; //Calculate value
    Return Value;
End Function CalculateFact;

Function CalculateFact1(FactX: Double; FactY: Double): Double;
Begin
    Return FactX / FactY;
End Function CalculateFact1;

The CubeClass, CurrentCoord and CurrentCube class static properties are used to access parameters of the current cube.

Function CalculateFact2: String;
Var
    Coord: IMatrixCoord;
    DimSelSet: IDimSelectionSet;
    DimInst: IDimInstance;
    DimIndex: Integer;
    ElementName: String;
Begin
    //Current coordinate
    Coord := CubeClass.CurrentCoord;
    DimSelSet := Coord.Matrix.Dimensions;
    //Calendar dimension data
    DimInst := DimSelSet.FindById("CALENDAR").Dimension;
    //Calendar dimension index in the list
    DimIndex := DimSelSet.IndexOfKey(DimInst.Key);
  //Element name in the dictionary ,to which the current coordinate corresponds
    ElementName := DimInst.Attributes.FindById("NAME").Value(Coord.Item(DimIndex));
    Return ElementName;
End Function CalculateFact2;

See also:

Examples | IStandardCubeFactBinding.Formula