Express > Express Assembly Interfaces > IEaxDataAreaHierarchies > IEaxDataAreaHierarchies.AddDependant
AddDependant(S: IDimSelection;
Key: Integer;
SS: IDimSelectionSet;
EId: String;
T: IEaxDataAreaTransformation);
S. The dimension that contains an alternative hierarchy.
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 the collection of alternative hierarchies, 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 a 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 fact dimension
custDim := hierarchy.CustomDimension;
// Get elements and indexes of fact dimension attributes
dimElems := custDim.Elements;
GetCustomDimensionAttributesIndexes(custDim, nameIndex, idIndex, orderIndex, keyIndex);
// Get maximum value
maxRow := GetMaxKey(custDim, keyIndex) + 1;
// Create a new index
newIndex := dimElems.Add;
// Set attribute value of fact dimension element
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 a 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 a formula to the collection of alternative hierarchies
hierarchies.AddDependant(ds, hKey, dss, strId, transform);
// Add an element to selection
ds.SelectElement(newIndex, False);
// Calculate analytical data area and refresh table
pivot.Refresh;
End Sub USerProc;
{ Get indexes of fact 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.
See also: