CalculatedElement(Index: Integer): Integer;
Index - index of the calculated element for this dimension.
The CalculatedElement property returns the unique identifier of the calculated element in dimension.
Index of the calculated element is passed by the Index parameter. A unique identifier is used for binding formatting style of calculated elements.
Executing the example requires a form with the button named Button1, the TabSheetBox component and the UiErAnalyzer component named UiErAnalyzer1, which is a data source for TabSheetBox.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
OLAP: IEaxAnalyzer;
Pivot: IPivot;
Dim: IDimInstance;
Calcs: IPivotEvaluatorDimCalculates;
CalcItem: IPivotEvaluatorDimCalculatesItem;
Sel: IDimSelection;
Elements: IDimElements;
i, j: Integer;
Element1, Element2, Element3: String;
EaxStyle: IEaxTableStyle;
Style, Style1: ITabCellStyle;
Begin
OLAP := UiErAnalyzer1.ErAnalyzer;
Pivot := OLAP.Pivot;
Dim := Pivot.TopHeader.Dim(0);
Calcs := Pivot.Evaluator.DimCalculates;
CalcItem := Calcs.FindByDimKey(Dim.Key);
Sel := Pivot.Selection.FindByKey(Dim.Key);
Elements := CalcItem.Dim.Elements;
Element1 := Elements.Id(Sel.Element(0));
Element2 := Elements.Id(Sel.Element(1));
Element3 := Elements.Id(Sel.Element(2));
i := CalcItem.AddCalculatedElement(Element1 + "+" + Element2, Sel.Element(1), DimRelation.Next);
CalcItem.Expression(i).AsString := "@" + Element1 + "+ @" + Element2;
j := CalcItem.AddCalculatedElement(Element1 + "+" + Element3, Sel.Element(2), DimRelation.Next);
CalcItem.Expression(j).AsString := "@" + Element1 + "+ @" + Element3;
//Formatting
EaxStyle := OLAP.Grid.Style;
Style := New TabCellStyle.Create;
Style1 := New TabCellStyle.Create;
Style.BackgroundBrush := New GxSolidBrush.Create(GxColor.FromName("Yellow"));
Style.HorizontalAlignment := TabFormatAlignment.Center;
Style.CustomFormat := "0,00";
Style1.Assign(Style);
Style1.BackgroundBrush := New GxSolidBrush.Create(GxColor.FromName("LightBlue"));
//Determine style for calculated element
EaxStyle.DimCalculateStyle(CalcItem.Dim.Key, CalcItem.CalculatedElement(i)) := Style;
EaxStyle.DimCalculateStyle(CalcItem.Dim.Key, CalcItem.CalculatedElement(j)) := Style1;
OLAP.Grid.Refresh;
End Sub Button1OnClick;
Clicking the button creates two calculated elements for the first dimension that is arranged in columns. These elements are placed after the second and the third dimension elements. Each calculated element has its own formatting style.
Source data:
A table with calculated elements:
See also: