Calculations: IAdoMdDimCalculations;
Calculations: Prognoz.Platform.Interop.Dimensions.IAdoMdDimCalculations;
The Calculations property returns collection of calculated dimension elements.
Executing the example requires that the repository contains an ADOMD directory with the ADOMDTest identifier, this directory contains the ADOMD cube - SALES. The cube structure must have dimensions based on ADOMD dictionaries with the DATE and COUNTRY identifiers.
Sub UserProc;
Var
MB: IMetabase;
CubeInst: ICubeInstance;
Dest: ICubeInstanceDestination;
SelSet: IDimSelectionSet;
Sel: IDimSelection;
DimSetup: ICubeExecuteDimSetup;
Calcs: IAdoMdDimCalculations;
Calc: IAdoMdDimCalculation;
Exec: ICubeInstanceDestinationExecutor;
AdoExec: IAdoMdCubeExecutor;
Mat: IMatrix;
Begin
MB := MetabaseClass.Active;
CubeInst := MB.ItemByIdNamespace("SALES", MB.GetObjectKeyById("ADOMDTest")).Open(Null) As ICubeInstance;
Dest := CubeInst.Destinations.DefaultDestination;
SelSet := Dest.CreateDimSelectionSet;
//Set selections
For Each Sel In SelSet Do
If Sel.Dimension.Ident = "COUNTRY" Then
DimSetup := CubeClass.SelectionSetup(Sel);
If DimSetup <> Null Then
DimSetup.GroupIndex := 2;
End If;
//Create a calculated element
Calcs := (DimSetup.Extension As IAdoMdExecuteDimSetup).Calculations;
Calc := Calcs.Add("");
Calc.Element(Sel.Dimension) := Sel.LastDimElement;
Calc.Expression := "SUM([DATE].[Year].Children)";
//Full selection
Sel.SelectAll;
Elseif Sel.Dimension.Ident = "DATE" Then
Sel.SelectElement(1, False);
DimSetup := CubeClass.SelectionSetup(Sel);
If DimSetup <> Null Then
DimSetup.GroupIndex := 1;
End If;
Else
Sel.SelectElement(1, False);
DimSetup := CubeClass.SelectionSetup(Sel);
If DimSetup <> Null Then
DimSetup.GroupIndex := 0;
End If;
End If
End For;
//Calculation
Exec := Dest.CreateExecutor;
AdoExec := Exec As IAdoMdCubeExecutor;
Exec.PrepareExecute(SelSet);
Exec.PerformExecute;
Mat := Exec.Matrix;
End Sub UserProc;
On executing the example a calculated element is added for the last element in the COUNTRY dimension. After this the cube is calculated, resulting matrix is available in the Mat variable.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.AdoMd;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.Metabase;
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
CubeInst: ICubeInstance;
Dest: ICubeInstanceDestination;
SelSet: IDimSelectionSet;
Sel: IDimSelection;
CubeCls: CubeClass = New CubeClassClass();
DimSetup: ICubeExecuteDimSetup;
Calcs: IAdoMdDimCalculations;
Calc: IAdoMdDimCalculation;
Exec: ICubeInstanceDestinationExecutor;
AdoExec: IAdoMdCubeExecutor;
Mat: IMatrix;
Begin
MB := Params.Metabase;
CubeInst := MB.ItemByIdNamespace["SALES", MB.GetObjectKeyById("ADOMDTest")].Open(Null) As ICubeInstance;
Dest := CubeInst.Destinations.DefaultDestination;
SelSet := Dest.CreateDimSelectionSet();
//Set selections
For Each Sel In SelSet Do
If Sel.Dimension.Ident = "COUNTRY" Then
DimSetup := CubeCls.SelectionSetup[Sel];
If DimSetup <> Null Then
DimSetup.GroupIndex := 2;
End If;
//Create a calculated element
Calcs := (DimSetup.Extension As IAdoMdExecuteDimSetup).Calculations;
Calc := Calcs.Add("");
Calc.Element[Sel.Dimension] := Sel.LastDimElement;
Calc.Expression := "SUM([DATE].[Year].Children)";
//Full selection
Sel.SelectAll();
Elseif Sel.Dimension.Ident = "DATE" Then
Sel.SelectElement(1, False);
DimSetup := CubeCls.SelectionSetup[Sel];
If DimSetup <> Null Then
DimSetup.GroupIndex := 1;
End If;
Else
Sel.SelectElement(1, False);
DimSetup := CubeCls.SelectionSetup[Sel];
If DimSetup <> Null Then
DimSetup.GroupIndex := 0;
End If;
End If
End For;
//Calculation
Exec := Dest.CreateExecutor();
AdoExec := Exec As IAdoMdCubeExecutor;
Exec.PrepareExecute(SelSet);
Exec.PerformExecute(False);
Mat := Exec.Matrix;
End Sub Main;
See also: