Data: IDatasetModel;
The Data property determines a relational data source or data consumer of multidimensional calculation on DB server.
Executing the example requires that the repository contains a database with the DB identifier. This database stores tables that have the following structure:
A table with the TABLE_INPUT identifier:
Field name | Purpose |
Data | Value input date. |
CityId | City identifiers, by which values are enclosed. |
Value | Factor value by the specified city. |
A table with the TABLE_OUTPUT identifier:
Field name | Purpose |
Data | Value input date. |
CountryId | Country identifiers, by which values are calculated. |
Value | Factor value by the country calculated regarding values by cities. |
The database also contains a table, on which the DIM1 dimension is based. This dimension is used to make hierarchical dependency between cities and countries. It is also used to create formulas by selected coordinates.
Add links to the Cubes, Db, Dimensions and Metabase system assemblies.
Sub UserProc;
Var
MB: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
MDCalc: IMDCalculation;
Destination: IMDCalculationDestination;
Source: IMDCalculationSource;
Slice: IMDCalculationSlice;
DimModel: IDimensionModel;
Fact: IMDCalculationfact;
FreeSlice: IMDCalculationSliceFree;
FixedSlice: IMDCalculationSliceFixed;
FormulasTable: IMDCalculationFormulasTable;
TableForFormulas: ITable;
Begin
// Get current repository
MB := MetabaseClass.Active;
// Create an object and set its parameters
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_MDCALCULATION;
CrInfo.Id := MB.GenerateId("MDCALC");
CrInfo.Name := "Multidimensional calculation on server";
CrInfo.Parent := Null;
MObj := MB.CreateObject(CrInfo).Edit;
MDCalc := MObj As IMDCalculation;
//Add a database
MDCalc.Database := MB.ItemById("DB").Bind As IDatabase;
//Add an input table
Source := MDcalc.Sources.Add(Mb.ItemById("TABLE_INPUT").Bind As IDatasetModel);
//Add a dimension for the "CityId" field of table
Slice := Source.Slices.Add;
Slice.Fields := "CITYID";
Slice.Name := "Cities";
Slice.FixType := MDCalculationSliceFixType.Free;
FreeSlice := Slice.Free;
//Link this dimension with the countries/cities dictionary
DimModel := MB.ItemById("DIM1").Bind As IDimensionModel;
FreeSlice.Dimension := DimModel;
FreeSlice.Index := DimModel.Blocks.Item(0).Indexes.Item(0);
//Add a calendar dimension
Slice := Source.Slices.Add;
Slice.Name := "Calendar";
Slice.Fields := "DATA";
Slice.FixType := MDCalculationSliceFixType.Fixed;
Slice.IsCalendar := True;
FixedSlice := Slice.Fixed;
//Add an indicator dimension
Fact := Source.Facts.Add;
Fact.FieldName := "VALUE";
Fact.Name := "Indicator";
//Add an output table
Destination := MDCalc.Destination;
Destination.Data := MB.ItemById("TABLE_OUTPUT").Bind As IDatasetModel;
//Add a dimension for the "CountryId" field of table
Slice := Destination.Slices.Add;
Slice.Fields := "COUNTRYID";
Slice.Name := "Countries/Cities";
Slice.FixType := MDCalculationSliceFixType.Free;
FreeSlice := Slice.Free;
//Link this dimension with the countries/cities dictionary
DimModel := Mb.ItemById("DIM1").Bind As IDimensionModel;
FreeSlice.Dimension := DimModel;
FreeSlice.Index := DimModel.Blocks.Item(0).Indexes.Item(0);
//Add a calendar dimension
Slice := Destination.Slices.Add;
Slice.Name := "Calendar";
Slice.Id := "CALEN";
Slice.Fields := "DATA";
Slice.FixType := MDCalculationSliceFixType.Fixed;
Slice.IsCalendar := True;
//Add an indicator dimension
Fact := Destination.Facts.Add;
Fact.FieldName := "VALUE";
Fact.Name := "Indicator";
//Specify link between fixed dimensions
FixedSlice.Mapping := Destination.Slices.FindById("CALEN");
//Create a new formulas table
FormulasTable := MDcalc.FormulasTable;
TableForFormulas := FormulasTable.Create;
FormulasTable.Attach(TableForFormulas);
MObj.Save;
End Sub UserProc;
After executing the example the Multidimensional Calculation on DB Server object is created in the repository root. The calculation is based on the values contained in the table with the TABLE_INPUT identifier. The table with the TABLE_OUTPUT is set as a destination. Necessary dimensions are created for table fields; factors linked to the VALUE fields are also created. Calendar dimensions are fixed. Summation by child elements can be set up in formulas by the CITYID field of the data source.
See also: