Show contents 

Cubes > Cubes Assembly Interfaces > IStandardCubeServerAggregation > IStandardCubeServerAggregation.CustomAggregateFunction

IStandardCubeServerAggregation.CustomAggregateFunction

Syntax

CustomAggregateFunction: String;

Description

The CustomAggregateFunction property determines a custom method of aggregation calculation.

Comments

This property is taken into account if the IStandardCubeServerAggregation.AggregationType property is set to CubeFactBindingAggregationType.Custom.

Example

Executing the example requires that the repository contains a standard cube with the OBJ_CUBE identifier. This cube must contain two dimensions.

Sub UserProc;
Var
    MB: IMetabase;
    CubeStdInst: IStandardCubeInstance;
    DestInst: ICubeInstanceDestination;
    Aggregator: IStandardCubeServerAggregator;
    StdDims: IStandardCubeDimensions;
    StdDim: IStandardCubeDimension;
    Aggregation: IStandardCubeServerAggregation;
    FactDimension: IDimInstance;
    Iter: IDimIterator;
    DimsEx: IStandardCubeServerAggregationDimensionsEx;
    AggDim: IStandardCubeServerAggregationDimension;
    MatrDS: IMatrixDataSource;
    DimSS: IDimSelectionSet;
    DimS: IDimSelection;
    Matr: IMatrix;
    Coord: IMatrixCoord;
    MatrIter: IMatrixIterator;
    i: Integer;
    s: String;
Begin

    MB := MetabaseClass.Active;
    CubeStdInst := MB.ItemById("OBJ_CUBE").Open(NullAs IStandardCubeInstance;
    DestInst := (CubeStdInst As ICubeInstance).Destinations.DefaultDestination;
    StdDims := DestInst.Dimensions As IStandardCubeDimensions;

    // Set up aggregation method
    Aggregator := CubeStdInst.CreateAggregator;
    FactDimension := (DestInst.DestinationModel As IStandardCubeDestination).FactDimension.OpenDimension;
    Iter := FactDimension.Elements.Elements.Iterator;
    Iter.First;
    While Iter.Next Do
        Aggregation := Aggregator.Aggregations.Add;
        Aggregation.AggregationType := CubeFactBindingAggregationType.Custom;
        Aggregation.CustomAggregateFunction := "SUM";
        Aggregation.FactKey := FactDimension.Indexes.PrimaryIndex.IndexAttributesValues(Iter.Element);
    End While;

    // Determine dimensions for aggregation
    DimsEx := Aggregator.Dimensions;
    AggDim := DimsEx.Item(0);
    AggDim.GroupIndex := 0;
    AggDim.Position := 0;
    AggDim.Others := True;
    AggDim := DimsEx.Item(1);
    AggDim.GroupIndex := 1;
    AggDim.Position := 0;
    AggDim.Totals := True;

    // Selection for aggregation calculation
    MatrDS := DestInst As IMatrixDataSource;
    DimSS := MatrDS.CreateDimSelectionSet;
    For Each DimS In DimSS Do
        DimS.SelectAll;
    End For;
    // Aggregation calculation
    Matr := Aggregator.Execute(DimSS);

    // Display aggregation results
    MatrIter := Matr.CreateIterator;
    MatrIter.Move(IteratorDirection.First);
    If MatrIter.Valid Then
        For i := 0 To StdDims.Count - 1 Do
            StdDim := StdDims.Item(i);
            If StdDim.FactDimension Then
                Debug.Write("Fact   ");
            Else
                Debug.Write(StdDim.OpenDimension.Name + "  ");
            End If;
        End For;
        Debug.Write("Aggregation  ");
        Debug.WriteLine("Value");
        Coord := Matr.CreateCoord;

        While MatrIter.Valid Do
            MatrIter.PutCurrentPos(Coord);
            s := "";
            For i := 0 To Coord.Count - 1 Do
                s := s + Coord.Item(i).ToString + "       ";
            End For;
            s := s + "= " + MatrIter.Value;
            Debug.WriteLine(s);
            MatrIter.Move(IteratorDirection.Next);
        End While;
    Else
        Debug.WriteLine("No data");
    End If;
End Sub UserProc;

After executing the example sum by dimensions is calculated for the cube facts. The calculation matrix is displayed in the console window.

View results

See also:

IStandardCubeServerAggregation