Consider the example of creating a standard cube with the use of the Fore language. To create a cube, the repository should contain the following objects:
A fact dictionary with the FACTS identifier.
A countries dictionary with the COUNTRY identifier.
A calendar dictionary with the CALENDAR identifier.
A table with the STD_DATA identifier that contains the following fields in its structure:
Value. Value in the specified point (Field type: Real).
Country_Key. Key of the country, for which a value is set (Field type: Integer).
V_date. Date, for which a value is specified (Field type: Date).
The below specified example creates a new object - Standard Cube - in the repository root folder and sets up its parameters:
The existing repository dictionary is set as a fact dimension.
One data source is added, the Value field of the data source is linked to the first cube fact.
Two dimensions are added to the cube structure: COUNTRY and CALENDAR.
The COUNTRY dimension is linked with the Country_Key field via the dictionary primary index; the CALENDAR dimension is linked with the V_date field via the primary index of the Years block.
A relation is created in the cube to set up calculated fact. This relation returns the previous point relative that, in which calculation is executed.
Based on the created relation the formula used for calculation is created for the second cube fact.
After that the cube is saved.
To execute the examples, add links to the Cubes, Db, Dimensions, and Metabase system assemblies.
Sub CreateStdCube;
Var
MB: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
StdCube: IStandardCube;
StdCubeDest: IStandardCubeDestination;
StdDims: IStandardCubeDimensions;
StdDatasets: IStandardCubeDatasets;
FactDim, CountryDim, CalendarDim: IStandardCubeDimension;
StdDataset: IStandardCubeDataset;
FactDimInst: IDimInstance;
KeyAttribute: IDimAttributeInstance;
FactBindings: IStandardCubeFactBindings;
DimBinding: IStandardCubeDimensionBinding;
DimIndex: IDimIndex;
Relation: IStandardCubeRelation;
DataSet_ID: String = "STD_DATA";
Begin
MB := MetabaseClass.Active;
//Information for creating a new repository object
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_STDCUBE;
CrInfo.Id := "New_Std_Cube";
CrInfo.Name := "New standard cube";
CrInfo.Parent := MB.Root;
//Create a cube
MObj := MB.CreateObject(CrInfo).Edit;
StdCube := MObj As IStandardCube;
//Set up cube parameters
StdCubeDest := StdCube.Destinations.Item(0);
StdDims := StdCubeDest.Dimensions;
StdDatasets := StdCubeDest.Datasets;
//Specify existing repository dictionary as a fact dimension
FactDim := StdDims.Add(MB.ItemById("FACTS").Bind As IDimensionModel);
StdCube.ExternalFactDimension := True;
FactDim.FactDimension := True;
//Add a data source
StdDataset := StdDatasets.Add(MB.ItemById(DataSet_ID).Bind As IDatasetModel);
//Link cube fact
FactDimInst := FactDim.OpenDimension;
KeyAttribute := FactDimInst.Attributes.FindById("KEY");
FactBindings := FactDim.FactBindings(StdDataset);
FactBindings.Binding(KeyAttribute.Value(0)).Formula.AsString := DataSet_ID + ".VALUE";
//Add dimensions
CountryDim := StdDims.Add(MB.ItemById("COUNTRY").Bind As IDimensionModel);
CalendarDim := StdDims.Add(MB.ItemById("CALENDAR").Bind As IDimensionModel);
//Link dimensions
//"Countries"
DimIndex := CountryDim.Dimension.Indexes.PrimaryIndex;
DimBinding := CountryDim.Binding(StdDataset);
DimBinding.Index := DimIndex;
DimBinding.Binding(DimIndex.Attributes.Item(0)).AsString := DataSet_ID + ".COUNTRY_KEY";
//"Calendar"
DimIndex := CalendarDim.Dimension.Blocks.Item("YEARS").Indexes.FindById("INDEX_BLOCK");
DimBinding := CalendarDim.Binding(StdDataset);
DimBinding.Index := DimIndex;
DimBinding.Binding(DimIndex.Attributes.Item(0)).AsString := DataSet_ID + ".V_DATE";
//Create and set up relations
Relation := StdCube.Relations.Add;
Relation.Name := "Shift for point";
Relation.Id := "BEFORE";
Relation.Relation(CalendarDim).AsString := "T.PREV";
//Specify formula for calculated fact
StdCube.CalcBindings.Binding(KeyAttribute.Value(1)).Formula.AsString := "@[" + KeyAttribute.Value(0) + "]-BEFORE[@[" + KeyAttribute.Value(0) + "]]";
MObj.Save;
End Sub CreateStdCube;
See also: