Creating and Setting Up a Calculated Series

Executing the example requires that the repository contains a workbook with the OBJ123 identifier to which a calculated series is added. At least two series must be added to the workbook to enable creating the calculated series. The example considers creating the calculated series values of which are the sum of the first and the second series.

Add links to the following system assemblies:

Fore Example

Sub UserProc;
Var
    MB: IMetabase;
    MObj: IMetabaseObject;
    Exp: IEaxAnalyzer;
    WB: ILaner;
    UsingSeries, UsingSeries2: ILanerSerie;
    NewSeries: ILanerCalculateSerie;
    Str: String;
    Trans: IFormulaTransformModel;
    ms: IMsFormulaTransform;
    TransformVar: IMsFormulaTransformVariable;
    Coord: IMsFormulaTransformCoord;
    Slice: IMsFormulaTransformSlice;
    selector: IMsFormulaTransformSelector;
    Formula: IMsFormula;
    Det: IMsDeterministicTransform;
    Term1, Term2: IMsFormulaTerm;
Begin
    MB := MetabaseClass.Active;
    //Open a workbook to edit
    MObj := MB.ItemById("OBJ123").Edit;
    Exp := MObj As IEaxAnalyzer;
    WB := Exp.Laner;
    WB.BeginUpdate;
    //Get the first and the second series of the workbook
    UsingSeries := WB.Series.Item(0As ILanerSerie;
    UsingSeries2 := WB.Series.Item(1As ILanerSerie;
    //Determine a title for the calculated series
    Str := "Summ_(" + UsingSeries.Name + " , " + UsingSeries2.Name + ")";
    //Create a calculated series
    NewSeries := WB.Series.AddCalculateSerie(Str);
    // Return the object that enables the user to set up parameters of the calculated series
    Trans := NewSeries.Transform;
    //Add data sources of the first and the second series of the workbook as input variables 
    Trans.AddInputVariable(UsingSeries.Stub);
    Trans.AddInputVariable(UsingSeries2.Stub);
    //Create model calculation object
    ms := Trans.Transform As IMsFormulaTransform;
    //Return the first output variable of the model calculation method
    TransformVar := ms.Outputs.Item(0);
    //Create the object containing parameters of the first output variable required to calculate the model
    Coord := ms.CreateCoord(TransformVar);
    // Add the object to collection of variable slices
    Slice := TransformVar.Slices.Add(Null);
    //Create the object containing properties used to select a variable slice, by which the calculation method is later set up
    Selector := ms.CreateSelector;
    //Define the variable slice, for which it is necessary to set up calculation method parameters
    Selector.Slice := Slice;
    // Create the object that enables the user to set up calculation method parameters
    Formula := ms.Transform(Selector);
    //Determine a model calculation method
    Formula.Kind := MsFormulaKind.Deterministic;
    //Determine the calculation step used in model calculation
    Formula.Level := DimCalendarLevel.Year;
    //Return parameters of the method used to calculate the model
    Det := Formula.Method As IMsDeterministicTransform;
    //Add a data source of the first series in the workbook to collection of input variable
    TransformVar := ms.Inputs.Add(UsingSeries.Stub);
    //Add the object to collection of variable slices
    Slice := TransformVar.Slices.Add(Null);
    //Add a data source of the first series in the workbook to collection of input variable
    TransformVar := ms.Inputs.Add(UsingSeries.Stub);
    // Add the object to collection of variable slices
    Slice := TransformVar.Slices.Add(Null);
    //Create the term for the model equation
    Term1 := Det.Operands.Add(Slice);
    //Add a data source of the first series in the workbook to collection of input variable
    TransformVar := ms.Inputs.Add(UsingSeries2.Stub);
    Slice := TransformVar.Slices.Add(Null);
    //Create the second  term for the model equation
    Term2 := Det.Operands.Add(Slice);
    //Create model equation
    Det.Expression.AsString := Term1.TermToInnerText + " + " + Term2.TermToInnerText;
    //Calculate the created series
    NewSeries.Calculate;
    WB.EndUpdate;
    MObj.Save;
End Sub UserProc;

After executing this example the new calculated series which is the sum of the two first series data is added.

Fore.NET Example

The defined procedure is the Main entry point in the Program module of the .NET assembly. The Express, Metabase, Laner, Cubes, Dimension, Ms assemblies must be imported to this module from the Prognoz.Platform.Interop system assembly.

Public Shared Sub Main(Params: StartParams);

Var 
    MB: IMetabase;
    MObj: IMetabaseObject;
    Exp: IEaxAnalyzer;
    WB: ILaner;
    UsingSeries, UsingSeries2: ILanerSerie;
    NewSeries: ILanerCalculateSerie;
    Str: String;
    Trans: IFormulaTransformModel;
    ms: IMsFormulaTransform;
    TransformVar: IMsFormulaTransformVariable;
    Coord: IMsFormulaTransformCoord;
    Slice: IMsFormulaTransformSlice;
    selector: IMsFormulaTransformSelector;
    Formula: IMsFormula;
    Det: IMsDeterministicTransform;
    Term1, Term2: IMsFormulaTerm;
Begin
    MB := Params.Metabase;
    //Open a workbook to edit
    MObj := MB.ItemById["OBJ123"].Edit();
    Exp := MObj As IEaxAnalyzer;
    WB := Exp.Laner;
    WB.BeginUpdate();
    //Get the first and the second series of the workbook
    UsingSeries := WB.Series.Item[0As ILanerSerie;
    UsingSeries2 := WB.Series.Item[1As ILanerSerie;
    //Determine a title for the calculated series
    Str := "Summ_(" + UsingSeries.Name + " , " + UsingSeries2.Name + ")";
    //Create a calculated series
    NewSeries := WB.Series.AddCalculateSerie(Str,  DimCalendarLevel.dclNone, -1);
    // Return the object that enables the user to set up parameters of the calculated series
    Trans := NewSeries.Transform;
    //Add data sources of the first and the second series of the workbook as input variables 
    Trans.AddInputVariable(UsingSeries.Stub);
    Trans.AddInputVariable(UsingSeries2.Stub);
    //Create model calculation object
    ms := Trans.Transform As IMsFormulaTransform;
    //Return the first output variable of the model calculation method
    TransformVar := ms.Outputs.Item[0];
    //Create the object containing parameters of the first output variable required to calculate the model
    Coord := ms.CreateCoord(TransformVar);
    // Add the object to collection of variable slices
    Slice := TransformVar.Slices.Add(Null);
    //Create the object containing properties used to select a variable slice, by which the calculation method is later set up
    Selector := ms.CreateSelector();
    //Define the variable slice, for which it is necessary to set up calculation method parameters
    Selector.Slice := Slice;
    // Create the object that enables the user to set up calculation method parameters
    Formula := ms.Transform[Selector];
    //Determine a model calculation method
    Formula.Kind := MsFormulaKind.mfkDeterministic;
    //Determine the calculation step used in model calculation
    Formula.Level := DimCalendarLevel.dclYear;
    //Return parameters of the method used to calculate the model
    Det := Formula.Method As IMsDeterministicTransform;
    //Add a data source of the first series in the workbook to collection of input variable
    TransformVar := ms.Inputs.Add(UsingSeries.Stub);
    //Add the object to collection of variable slices
    Slice := TransformVar.Slices.Add(Null);
    //Add a data source of the first series in the workbook to collection of input variable
    TransformVar := ms.Inputs.Add(UsingSeries.Stub);
    // Add the object to collection of variable slices
    Slice := TransformVar.Slices.Add(Null);
    //Create the term for the model equation
    Term1 := Det.Operands.Add(Slice);
    //Add a data source of the first series in the workbook to collection of input variable
    TransformVar := ms.Inputs.Add(UsingSeries2.Stub);
    Slice := TransformVar.Slices.Add(Null);
    //Create the second  term for the model equation
    Term2 := Det.Operands.Add(Slice);
    //Create model equation
    Det.Expression.AsString := Term1.TermToInnerText() + " + " + Term2.TermToInnerText();
    //Calculate the created series
    NewSeries.Calculate();
    WB.EndUpdate();
    MObj.Save();
End Sub;

The result of example execution matches with that of the Fore example.

See also:

Examples | ILaner | ILanerSeries | ILanerCalculateSerie