AddPercentCalculate(
Name: String;
RelationElement: Integer;
Relation: DimRelation;
TotalDisposition: PivotEvaluatorTotalDisposition;
TotalType: PivotEvaluatorElementType): Integer;
Name. Name of created calculated element.
RelationElement. Dimension element referring to which calculated element is positioned.
Relation. Insert position of calculated element referring to the RelationElement element.
TotalDisposition. Disposition of totals referring to which calculated factor is calculated.
TotalType. Type of totals referring to which calculated factor is calculated. Calculated factor calculation requires calculating this totals type in the table.
The AddPercentCalculate method creates a calculated factor that calculates percentage value of a cell relatively to a total value.
Executing the example requires a form with the button named Button1, the UiErAnalyzer component named UiErAnalyzer1, any components 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 this example, clicking the button activates calculation of totals for an express report, loaded into UiErAnalyzer1. Values sum is calculated by rows. Intermediate values of totals are also calculated. Two calculated elements, performing 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 intermediate totals. Display format is set for calculated factors.
Source data:
Table with calculated elements:
See also: