IPivotEvaluatorDimCalculatesItem.AddPercentCalculate

Syntax

AddPercentCalculate(

Name: String;

RelationElement: Integer;

Relation: DimRelation;

TotalDisposition: PivotEvaluatorTotalDisposition;

TotalType: PivotEvaluatorElementType): Integer;

Parameters

Name. Name of created calculated element.

RelationElement. Dimension element, relative to which a calculated element is placed.

Relation. Insert position of calculated element relative to the RelationElement element.

TotalDisposition. Type of totals, relative to which calculated factor is calculated.

TotalType. Type of totals, relative to which calculated factor is calculated. Calculated factor calculation requires calculating this totals type in the table.

Description

The AddPercentCalculate method creates a calculated factor that calculates percentage value of a cell relative to a total value.

Example

Executing the example requires a form with the button named Button1, the UiErAnalyzer component named UiErAnalyzer1, any components that are used to display data of the report loaded to UiErAnalyzer1, for example, TabSheetBox.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    OLAP: IEaxAnalyzer;
    Grid: IEaxGrid;
    Pivot: IPivot;
    Sel: IDimSelection;
    Totals: IPivotEvaluatorTotals;
    Dim: IDimInstance;
    Calcs: IPivotEvaluatorDimCalculates;
    Calc: IPivotEvaluatorDimCalculatesItem;
    Style: ITabCellStyle;
    i, i1: Integer;
Begin
    OLAP := UiErAnalyzer1.ErAnalyzer;
    Grid := OLAP.Grid;
    Pivot := OLAP.Pivot;
    //Totals
    Totals := Pivot.Evaluator.Totals;
    Totals.RowTypes := PivotEvaluatorElementType.Sum;
    //Calculated factor - Percentage to total
    Dim := Pivot.TopHeader.Dim(0);
    Calcs := Pivot.Evaluator.DimCalculates;
    Calc := Calcs.FindByDimKey(Dim.Key);
    Sel := Pivot.Selection.FindByKey(Dim.Key);
    i := Calc.AddPercentCalculate("Percentage to total", Sel.Element(0), DimRelation.Last,
        PivotEvaluatorTotalDisposition.Overall, PivotEvaluatorElementType.Sum);
    i1 := Calc.AddPercentCalculate("Percentage to subtotal", Sel.Element(0), DimRelation.Last,
        PivotEvaluatorTotalDisposition.Sub_, PivotEvaluatorElementType.Sum);
    //Set up format
    Style := New TabCellStyle.Create;
    Style.BackgroundBrush := New GxSolidBrush.Create(GxColor.FromName("Coral"));
    Style.Font.Bold := TriState.OnOption;
    Style.CustomFormat := "0,00%";
    //Determine style for calculated elements
    Grid.Style.DimCalculateStyle(Dim.Key, Calc.CalculatedElement(i)) := Style;
    Grid.Style.DimCalculateStyle(Dim.Key, Calc.CalculatedElement(i1)) := Style;
    Grid.Refresh;
End Sub Button1OnClick;

After executing the example clicking the button activates calculation of totals for an express report loaded into UiErAnalyzer1. Values sum is calculated by rows. Subtotals values are also calculated. Two calculated elements, executing calculation on a base of values of the first factor that is in a selection for the first column, are created. The first calculated factor calculates percentage of values to general totals, the second one calculates percentage of subtotals. Display format is set for calculated factors.

Source data:

A table with calculated elements:

See also:

IPivotEvaluatorDimCalculatesItem