Fact dimension is an integral part of different types of cubes. On setting element binding of fact dimension in cubes, the place of actual storage of values by various indexes is determined. Different cubes use different types of fact dimensions. In this section we consider working with fact local dimension of cube.
Fact local dimension is available in standard and calculated cubes. Designed dictionary, which is created as hidden child object of the cube, is in the base of local fact dimension. The IDimensionModel interface can be used to view information on the structure of the fact dimension. The ICustomDimension interface is used to edit structure and set tree of elements.
The example of access to the fact local dimension in standard cube:
Var
//...
MB: IMetabase;
StdCube: IStandardCube;
CalcCube: ICalculatedCube;
FactDim: ICustomDimension;
//...
Begin
//...
MB := MetabaseClass.Active;
StdCube := MB.ItemById("StdCube_1").Edit As IStandardCube;
//Set whether local fact dimension is used in cube
StdCube.ExternalFactDimension := False;
//Get structure of local fact dimension
FactDim := StdCube.FactDimension.Dimension As ICustomDimension;
//...
Example of access to the structure of fact local dimension in a calculated cube:
Var
//...
MB: IMetabase;
CalcCube: ICalculatedCube;
FactDim: ICustomDimension;
//...
Begin
//...
MB := MetabaseClass.Active;
CalcCube := MB.ItemById("CalcCube_1").Edit As ICalculatedCube;
//Set whether local fact dimension is used in cube
CalcCube.ExternalFactDimension := False;
//Get structure of local fact dimension
FactDim := CalcCube.InternalFactDimension;
//...
Fact dimension automatically contains three basic attributes:
Attribute index | Attribute identifier. | Attribute name | Attribute destination |
0 | KEY | Key | ID, Primary key |
1 | NAME | Name | Name |
2 | ORDER | Order | Order |
If necessary, attribute list can be changed. The ICustomDimAttributes interface is used to work with the collection of fact dimension attributes.
Var
//...
FactDim: ICustomDimension;
CAttrs: ICustomDimAttributes;
CAttr: ICustomDimAttribute;
//...
Begin
//...
CAttrs := FactDim.Attributes;
CAttr := CAttrs.Add;
CAttr.Id := "IMAGEATTR";
CAttr.Name := "Element icon";
CAttr.DataType := DbDataType.Integer;
CAttrs.ImageIndex := CAttr;
//...
NOTE. If the set of basic attributes in fact dimension is changed, the further correct performance of fact dimension requires creating and setting of the following attributes: ID, Primary key, Name, Order. After recreating any basic attribute, all the elements should contain new values by this attribute.
Example of recreating a basic attribute:
Var
//...
FactDim: ICustomDimension;
Attrs: ICustomDimAttributes;
Attr: ICustomDimAttribute;
Elements: ICustomDimElements;
Element: Integer;
//...
Begin
//...
//Get attribute list
Attrs := FactDim.Attributes;
//Create a new attribute
Attr := Attrs.Add;
Attr.DataType := DbDataType.Integer;
Attr.Id := "UserKey";
Attr.Name := "Custom primary key";
//Use a new attribute as primary key
Attrs.Primary := Attr;
//Get list of existing elements
Elements := FactDim.Elements;
For Element := 0 To Elements.RowCount - 1 Do
//Using new primary key , new unique values should be created
//Knowing that attributes are added to the end of the list, the value will be set
//by the last attribute
Elements.AttributeValue(Element, Elements.AttributeCount - 1) := 1000 + Element;
End For;
//...
The ICustomDimLevels interface is used to work with the collection of fact dimension levels.
Var
//...
CustDim: ICustomDimension;
CustLevels: ICustomDimLevels;
CustLevel: ICustomDimLevel;
//...
Begin
//...
//Level list
CustLevels := CustDim.Levels;
CustLevels.Clear;
CustLevel := CustLevels.Add;
CustLevel.Id := "LVL1";
CustLevel.Name := "First level";
CustLevel := CustLevels.Add;
CustLevel.Id := "LVL2";
CustLevel.Name := "Second level";
//...
The OrganizeLevels method can also be used for automatic organization of level list according to existing hierarchy of elements.
Working with elements of fact dimension is organizing element hierarchy and setting attribute values. The list of elements is available as a collection, or a tree.
To get the list of fact dimension elements as a collection, use the Elements property. Every element is located in a separate string. New elements are created on the top of hierarchy. The Add method is used to create new elements. After creating a new element, the AttributeValue property determines values for all the attributes. The Owner property is used to set up elements hierarchy in the collection.
Var
//...
CustDim: ICustomDimension;
Elements: ICustomDimElements;
Row: Integer;
//...
Begin
//...
//Collection of elements
Elements := CustDim.Elements;
//Create a new element
Row := Elements.Add;
//Install attribute values. It is supposed that lists of attributes is not modified
Elements.AttributeValue(Row, 0) := Row;
Elements.AttributeValue(Row, 1) := "New values";
Elements.AttributeValue(Row, 2) := Row;
//...
To get the list of fact dimension elements shaped as a tree, use the Tree property. The list of root elements is available in the RootChildren property. The Owner property is used to set the hierarchy of existing elements. On creating new elements the Add method shows primary key of parental element. After creating element the AttributeValue property determines values of all the attributes.
Var
//...
CustDim: ICustomDimension;
Tree: ICustomDimTree;
Root, Child: Integer;
//...
Begin
//...
//Element tree
Tree := CustDim.Tree;
//Create root element
Root := Tree.Add(Null);
//Install attribute values. It is supposed that lists of attributes is not modified
Tree.AttributeValue(Root, 0) := Root;
Tree.AttributeValue(Root, 1) := "Root element";
Tree.AttributeValue(Root, 2) := Root;
//Create child element
Child := Tree.Add(Root);
//Install attribute values. It is supposed that lists of attributes is not modified
Tree.AttributeValue(Child, 0) := Child;
Tree.AttributeValue(Child, 1) := "Child element";
Tree.AttributeValue(Child, 2) := Child;
//...
See also: