CalcTransformations: IEaxDataAreaTransformations;
CalcTransformations: Prognoz.Platfrorm.Interop.Express.IEaxDataAreaTransformations;
The CalcTransformations property returns collection of data transformation formulas set for calculated elements.
Calculated elements are created in designed dictionary of separate alternative hierarchy. Alternative hierarchy should be created for the dimension where calculated elements should be used. For each calculated element in the CalcTransformations collection, specific formula of data transformation is created used to calculate values.
Executing the example requires that the repository contains a regular report with the REPORT identifier. An analytical data area is created in the report, there is a dimension with the REGIONS identifier among source dimensions.
Link the Dal, Dimensions, Express, Metabase, Report system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Report: IPrxReport;
DataArea: IEaxDataArea;
DataAreaSlice: IEaxDataAreaSlice;
DimSS: IDimSelectionSet;
DimS: IDimSelection;
Hierarchies: IEaxDataAreaHierarchies;
Hierarchy: IEaxDataAreaHierarchy;
CustomDim: ICustomDimension;
Elements: ICustomDimElements;
Attributes: ICustomDimAttributes;
NameAttribute: ICustomDimAttribute;
Transform: IEaxDataAreaTransformation;
hKey, newElIndex, ElId: Integer;
Begin
MB := MetabaseClass.Active;
Report := MB.ItemById("REPORT").Edit As IPrxReport;
DataArea := Report.DataArea As IEaxDataArea;
DataAreaSlice := DataArea.Slices.Item(0);
//Source dimension
DimSS := DataAreaSlice.Selection;
DimS := DimSS.FindById("REGIONS");
//Create calculated element basing on created parameter
Hierarchies := DataArea.Hierarchies;
//Unique key of hierarchy
hKey := Hierarchies.CreateKey(DataAreaSlice.Key, DimS.Dimension.Key);
//Get alternative hierarchy by its key
Hierarchy := Hierarchies.FindByKey(hKey);
//If hierarchy is not found by key, then create it
If Hierarchy = Null Then
Hierarchy := Hierarchies.Add(DataAreaSlice, DimS, hKey);
End If;
//Get facts dimension
CustomDim := Hierarchy.CustomDimension;
//Get elements and indexes of fact dimension attributes
Elements := CustomDim.Elements;
Attributes := CustomDim.Attributes;
NameAttribute := Attributes.Name;
//Creating a new element
newElIndex := Elements.Add;
ElId := Elements.RowCount + 1;
//Attribute values for new element
Elements.AttributeValueByKey(newElIndex, NameAttribute.Key) := "Calculated element";
Elements.AttributeValueByKey(newElIndex, Attributes.Id.Key) := ElId.ToString;
Elements.AttributeValueByKey(newElIndex, Attributes.Order.Key) := ElId;
//Applying of changes to dimension with alternative hierarchy
Hierarchies.PushChangesToDimInstance(DimS, CustomDim);
newElIndex := DimS.Dimension.Elements.FindById(ElId.ToString);
//Transformation formula for calculated element
Transform := DataAreaSlice.CalcTransformations.Add(DimSS, DimS, newElIndex);
Transform.Enabled := True;
Transform.Expression.AsString := '{' + Elements.AttributeValueByKey(0, NameAttribute.Key) + "[t]}+{" + Elements.AttributeValueByKey(1, NameAttribute.Key) + "[t]}";
Hierarchies.AddDependant(DimS, hKey, DimSS, ElId.ToString, Transform);
//Saving
Report.MetabaseObject.Save;
End Sub UserProc;
On executing the example the analytical data area slice is extended:
An alternative hierarchy with added calculated element is created for the REGIONS dimension.
A transformation formula used to sum up values of two first dimension elements is set for the calculated element.
The requirements and result of the Fore.NET Example execution match with those in the Fore Example.
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Express;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Report;
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
Report: IPrxReport;
DataArea: IEaxDataArea;
DataAreaSlice: IEaxDataAreaSlice;
DimSS: IDimSelectionSet;
DimS: IDimSelection;
Hierarchies: IEaxDataAreaHierarchies;
Hierarchy: IEaxDataAreaHierarchy;
CustomDim: ICustomDimension;
Elements: ICustomDimElements;
Attributes: ICustomDimAttributes;
NameAttribute: ICustomDimAttribute;
Transform: IEaxDataAreaTransformation;
hKey, elIndex: uinteger;
newElIndex, ElId: Integer;
Begin
MB := Params.Metabase;
Report := MB.ItemById["REPORT"].Edit() As IPrxReport;
DataArea := Report.DataArea As IEaxDataArea;
DataAreaSlice := DataArea.Slices.Item[0];
//Source dimension
DimSS := DataAreaSlice.Selection;
DimS := DimSS.FindById("REGIONS");
//Create calculated element basing on created parameter
Hierarchies := DataArea.Hierarchies;
//Unique key of hierarchy
hKey := Hierarchies.CreateKey(DataAreaSlice.Key, DimS.Dimension.Key);
//Get alternative hierarchy by its key
Hierarchy := Hierarchies.FindByKey(hKey);
//If hierarchy is not found by key, then create it
If Hierarchy = Null Then
Hierarchy := Hierarchies.Add(DataAreaSlice, DimS, hKey, Null);
End If;
//Get facts dimension
CustomDim := Hierarchy.CustomDimension;
//Get elements and indexes of fact dimension attributes
Elements := CustomDim.Elements;
Attributes := CustomDim.Attributes;
NameAttribute := Attributes.Name;
//Creating a new element
newElIndex := Elements.Add();
ElId := Elements.RowCount + 1;
//Attribute values for new element
Elements.AttributeValueByKey[newElIndex, NameAttribute.Key] := "Calculated element";
Elements.AttributeValueByKey[newElIndex, Attributes.Id.Key] := ElId.ToString();
Elements.AttributeValueByKey[newElIndex, Attributes.Order.Key] := ElId;
//Applying of changes to dimension with alternative hierarchy
Hierarchies.PushChangesToDimInstance(DimS, CustomDim);
elIndex := DimS.Dimension.Elements.FindById(ElId.ToString());
//Transformation formula for calculated element
Transform := DataAreaSlice.CalcTransformations.Add(DimSS, DimS, elIndex);
Transform.Enabled := True;
Transform.Expression.AsString := '{' + Elements.AttributeValueByKey[0, NameAttribute.Key] + "[t]}+{" + Elements.AttributeValueByKey[1, NameAttribute.Key] + "[t]}";
Hierarchies.AddDependant(DimS, hKey, DimSS, ElId.ToString(), Transform);
//Saving
Report.MetabaseObject.Save();
End Sub;
See also: