AddDependant(S: IDimSelection;
Key: Integer;
SS: IDimSelectionSet;
EId: String;
T: IEaxDataAreaTransformation);
AddDependant (S: Prognoz.Platform.Interop.Dimensions.IDimSelection;
Key: uinteger;
SS: IDimSelectionSet;
EId: string;
T: IEaxDataAreaTransformation);
S. Dimension where alternative hierarchy is placed.
Key. Dimension key.
SS. Dimension selection.
EId. Dimension element identifier.
T. Data transformation formula.
The AddDependant method adds formula of data transformation in alternative hierarchy collection.
To remove data transformation formula from alternative hierarchy collection, use IEaxDataAreaHierarchies.RemoveDependant.
Executing the example requires that the repository contains an express report with the EXPRESS identifier. One of data source dimensions contains alternative hierarchy.
Add links to the Dimensions, Express, Metabase, Ms, Pivot system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Eax: IEaxAnalyzer;
pivot: IPivot;
slice: IEaxDataAreaSlice;
transformations: IEaxDataAreaTransformations;
dss: IDimSelectionSet;
ds: IDimSelection;
hierarchies: IEaxDataAreaHierarchies;
custDim: ICustomDimension;
da: IEaxDataArea;
transform: IEaxDataAreaTransformation;
dimElems: ICustomDimElements;
newIndex: Integer;
nameIndex, idIndex, orderIndex, keyIndex: Integer;
maxRow: Integer;
strId: String;
elements: IDimElements;
hierarchy: IEaxDataAreaHierarchy;
hKey: Integer;
Begin
// Get repository
MB := MetabaseClass.Active;
// Get express report
Eax := MB.ItemById("EXPRESS").Edit As IEaxAnalyzer;
// Get data table
pivot := Eax.Pivot;
// Get data slice
slice := Eax.DataArea.Slices.Item(0);
// Get dimension selection
dss := slice.Selection;
// Get dimension
ds := dss.Item(0);
Debug.WriteLine("Dimension name - " + ds.Dimension.Name);
If ds = Null Then
Return;
End If;
// Get analytical data area
da := slice.Slices.DataArea;
If da = Null Then
Return;
End If;
// Get collection of alternative hierarchies
hierarchies := da.Hierarchies;
// Create unique hierarchy key
hKey := hierarchies.CreateKey(slice.Key, ds.Dimension.Key);
// Get alternative hierarchy by its key
hierarchy := hierarchies.FindByKey(hKey);
// If hierarchy is not found by key, create it
If hierarchy = Null Then
hierarchy := hierarchies.Add(slice, ds, hKey);
End If;
// Get facts dimension
custDim := hierarchy.CustomDimension;
// Get elements and indexes of facts dimension attributes
dimElems := custDim.Elements;
GetCustomDimensionAttributesIndexes(custDim, nameIndex, idIndex, orderIndex, keyIndex);
// Get maximum value
maxRow := GetMaxKey(custDim, keyIndex) + 1;
// Create new index
newIndex := dimElems.Add;
// Set value of facts dimension element attribute
dimElems.AttributeValue(newIndex, nameIndex) := "New element + " + datetime.Now.ToString;
strId := "NEW_ELEMENT_" + maxRow.ToString;
dimElems.AttributeValue(newIndex, idIndex) := strId;
dimElems.AttributeValue(newIndex, orderIndex) := dimElems.RowCount + 1;
dimElems.AttributeValue(newIndex, keyIndex) := maxRow;
// Apply changes to dimension with alternative hierarchy
hierarchies.PushChangesToDimInstance(ds, CustDim);
elements := ds.Dimension.Elements;
newIndex := elements.FindById(strId);
// Get collection of calculated transformations
transformations := slice.CalcTransformations;
// Add transformation, enable it and set formula
transform := transformations.Add(dss, ds, newIndex);
transform.Enabled := True;
transform.Expression.AsString := "average({Value}, setperiod(1989,1993))";
(transform.OutputPeriod As IMsDatePeriod).AutoPeriod := MsDateAutoPeriodOptions.None;
(transform.OutputPeriod As IMsDatePeriod).Start := DateTime.ComposeDay(1990, 1, 1);
(transform.OutputPeriod As IMsDatePeriod).End_ := DateTime.ComposeDay(1990, 12, 31);
// Add formula in collection of alternative hierarchies
hierarchies.AddDependant(ds, hKey, dss, strId, transform);
// Add element in selection
ds.SelectElement(newIndex, False);
// Calculate analytical data area and refresh table
pivot.Refresh;
End Sub USerProc;
{ Get indexes of facts dimension attributes }
Sub GetCustomDimensionAttributesIndexes(customDimension: ICustomDimension; Var nameIndex, idIndex, orderIndex, keyIndex: Integer);
Var
dimElems: ICustomDimElements;
attributes: ICustomDimAttributes;
attribute: ICustomDimAttribute;
i, count: Integer;
name, id, order, pKey: ICustomDimAttribute;
Begin
If customDimension = Null Then
Return;
End If;
dimElems := customDimension.Elements;
attributes := customDimension.Attributes;
name := attributes.Name;
id := attributes.Id;
order := attributes.Order;
pKey := attributes.Primary;
count := attributes.Count;
For i := 0 To count - 1 Do
attribute := attributes.Item(i);
If attribute = name Then
nameIndex := i;
Continue;
End If;
If attribute = id Then
idIndex := i;
Continue;
End If;
If attribute = order Then
orderIndex := i;
Continue;
End If;
If attribute = pKey Then
keyIndex := i;
Continue;
End If;
End For;
End Sub GetCustomDimensionAttributesIndexes;
{ Get maximum key }
Function GetMaxKey(customDimension: ICustomDimension; attributeId: Integer): Integer;
Var
dimElems: ICustomDimElements;
max, item: Integer;
i, count: Integer;
Begin
If customDimension = Null Then
Return - 1;
End If;
dimElems := customDimension.Elements;
count := dimElems.RowCount;
If count > 0 Then
max := dimElems.AttributeValue(i, attributeId);
For i := 1 To count - 1 Do
item := dimElems.AttributeValue(i, attributeId);
If item > max Then
max := item;
End If;
End For;
If count > max Then
max := count;
End If;
Return max;
End If;
Return - 1;
End Function GetMaxKey;
After executing the example data transformation formula is added in collection of alternative hierarchies.
The requirements and result of the Fore.NET Example execution match with those in the Fore Example. Use Fore.NET analogs instead of Fore components.
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Express;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Pivot;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
Eax: IEaxAnalyzer;
pivot: IPivot;
slice: IEaxDataAreaSlice;
transformations: IEaxDataAreaTransformations;
dss: IDimSelectionSet;
ds: IDimSelection;
hierarchies: IEaxDataAreaHierarchies;
custDim: ICustomDimension;
da: IEaxDataArea;
transform: IEaxDataAreaTransformation;
dimElems: ICustomDimElements;
newIndex: integer;
nameIndex, idIndex, orderIndex, keyIndex: Integer;
maxRow: Integer;
strId: String;
elements: IDimElements;
hierarchy: IEaxDataAreaHierarchy;
hKey: uinteger;
Begin
// Get repository
MB := Params.Metabase;
// Get express report
Eax := MB.ItemById["EXPRESS"].Edit() As IEaxAnalyzer;
// Get data table
pivot := Eax.Pivot;
// Get data slice
slice := Eax.DataArea.Slices.Item[0];
// Get dimension selection
dss := slice.Selection;
// Get dimension
ds := dss.Item[0];
System.Diagnostics.Debug.WriteLine("Dimension name - " + ds.Dimension.Name);
If ds = Null Then
Return;
End If;
// Get analytical data area
da := slice.Slices.DataArea;
If da = Null Then
Return;
End If;
// Get collection of alternative hierarchies
hierarchies := da.Hierarchies;
// Create unique hierarchy key
hKey := hierarchies.CreateKey(slice.Key, ds.Dimension.Key);
// Get alternative hierarchy by its key
hierarchy := hierarchies.FindByKey(hKey);
// If hierarchy is not found by key, create it
If hierarchy = Null Then
hierarchy := hierarchies.Add(slice, ds, hKey, Null);
End If;
// Get facts dimension
custDim := hierarchy.CustomDimension;
// Get elements and indexes of facts dimension attributes
dimElems := custDim.Elements;
GetCustomDimensionAttributesIndexes(custDim, Var nameIndex, Var idIndex, Var orderIndex, Var keyIndex);
// Get maximum value
maxRow := GetMaxKey(custDim, keyIndex) + 1;
// Create new index
newIndex := dimElems.Add() As Integer;
// Set value of facts dimension element attribute
dimElems.AttributeValue[newIndex, nameIndex] := "New element + " + datetime.Now.ToString();
strId := "NEW_ELEMENT_" + maxRow.ToString();
dimElems.AttributeValue[newIndex, idIndex] := strId;
dimElems.AttributeValue[newIndex, orderIndex] := dimElems.RowCount + 1;
dimElems.AttributeValue[newIndex, keyIndex] := maxRow;
// Apply changes to dimension with alternative hierarchy
hierarchies.PushChangesToDimInstance(ds, CustDim);
elements := ds.Dimension.Elements;
newIndex := elements.FindById(strId) As Integer;
// Get collection of calculated transformations
transformations := slice.CalcTransformations;
// Add transformation, enable it and set formula
transform := transformations.Add(dss, ds, newIndex As uinteger);
transform.Enabled := True;
transform.Expression.AsString := "average({Value}, setperiod(1989,1993))";
(transform.OutputPeriod As IMsDatePeriod).AutoPeriod := MsDateAutoPeriodOptions.msdapoNone As Integer;
(transform.OutputPeriod As IMsDatePeriod).Start := DateTime.Parse("1989, 1, 1");
(transform.OutputPeriod As IMsDatePeriod).@End := DateTime.Parse("1990, 12, 31");
// Add formula in collection of alternative hierarchies
hierarchies.AddDependant(ds, hKey, dss, strId, transform);
// Add element in selection
ds.SelectElement(newIndex As uinteger, False);
// Calculate analytical data area and refresh table
pivot.Refresh();
End Sub;
{ Get indexes of facts dimension attributes }
Public Shared Sub GetCustomDimensionAttributesIndexes(customDimension: ICustomDimension; Var nameIndex, idIndex, orderIndex, keyIndex: Integer);
Var
dimElems: ICustomDimElements;
attributes: ICustomDimAttributes;
attribute: ICustomDimAttribute;
i, count: Integer;
name, id, order, pKey: ICustomDimAttribute;
Begin
If customDimension = Null Then
Return;
End If;
dimElems := customDimension.Elements;
attributes := customDimension.Attributes;
name := attributes.Name;
id := attributes.Id;
order := attributes.Order;
pKey := attributes.Primary;
count := attributes.Count;
For i := 0 To count - 1 Do
attribute := attributes.Item[i];
If attribute = name Then
nameIndex := i;
Continue;
End If;
If attribute = id Then
idIndex := i;
Continue;
End If;
If attribute = order Then
orderIndex := i;
Continue;
End If;
If attribute = pKey Then
keyIndex := i;
Continue;
End If;
End For;
End Sub GetCustomDimensionAttributesIndexes;
{ Get maximum key }
Public Shared Function GetMaxKey(customDimension: ICustomDimension; attributeId: Integer): Integer;
Var
dimElems: ICustomDimElements;
max, item: Integer;
i, count: Integer;
Begin
If customDimension = Null Then
Return - 1;
End If;
dimElems := customDimension.Elements;
count := dimElems.RowCount;
If count > 0 Then
max := dimElems.AttributeValue[i, attributeId].GetHashCode();
For i := 1 To count - 1 Do
item := dimElems.AttributeValue[i, attributeId].GetHashCode();
If item > max Then
max := item;
End If;
End For;
If count > max Then
max := count;
End If;
Return max;
End If;
Return - 1;
End Function GetMaxKey;
See also: