Day(Calendar: IDimInstance; El: Integer): Integer;
Day(Calendar: Prognoz.Platform.Interop.Dimensions.IDimInstance; El: uinteger): uinteger;
Calendar. Data of the calendar dictionary, by which calculation is executed.
El. Index of the element, relative to which calculation is executed.
The Day method returns the index of the element that correlates to the start of a calendar period containing the specified element.
For correct calculation the calendar dictionary must contain the Days level.
For example, if the calendar dictionary contains Years, Quarters, Days levels and the calculation is executed for:
Element of the quarterly frequency, the Day method returns the element corresponding to the start of the quarter.
Element of the annual frequency, the Day method returns the element corresponding to the start of the year.
The example is the function that is used to calculate relations in a standard cube.
To execute the example, make sure that the repository contains a table with data by days, a calendar dictionary containing the Days level, and a standard cube. Set up the following for the standard cube:
On the Facts page set two facts: Value and Previous year.
On the Fact Binding page add a table to data sources and bind the table's numeric field with the Value fact.
On the Dimensions page add as a cube dimension calendar dictionary and bind dimension to data source field containing date, by the Primary Key of Days Block index.
Add links to the Cubes, Dimensions system assemblies.
Function GetLag(DimInst: IDimInstance; El: Integer): Integer;
Var
Result: Integer;
Begin
// Calculate
If CalendarDimension.Level(DimInst, El) = DimCalendarLevel.Day Then
Result := CalendarDimension.Day(DimInst, CalendarDimension.Shift(DimInst, El, 365));
Else
Result := -1;
End If;
// Return the result
Return Result;
End Function GetLag;
Public Function Lag(T: Variant): Variant;
Var
Cube: ICubeInstance;
CubeDest: ICubeInstanceDestination;
DimInsts: ICubeInstanceDimensions;
DimInst: IDimInstance;
Res: Array Of Integer;
I: Integer;
Cnt: Integer;
Begin
// Get current cube
Cube := CubeClass.CurrentCube;
CubeDest := Cube.Destinations.DefaultDestination;
// Find calendar dimension
DimInsts := CubeDest.Dimensions;
Cnt := DimInsts.Count;
For I := 0 To Cnt - 1 Do
If DimInsts.Item(I).Dimension.IsCalendar Then
DimInst := DimInsts.Item(I);
End If;
End For;
// Determine whether it is possible to have an array as input parameter T
If T.VarType = ForeVariantType.Matrix Then
Res := T As Array Of Integer;
Cnt := Res.Length;
For I := 0 To Cnt - 1 Do
Res[I] := GetLag(DimInst, Res[I]);
End For;
// Return result
Return Res;
Else
//Return integer value
Return GetLag(DimInst, T);
End If;
End Function Lag;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
…
Function GetLag(DimInst: IDimInstance; El: Integer): Integer;
Var
Result: Integer;
CalendarDimension: CalendarDimension;
Begin
// Calculate
If CalendarDimension.Level(DimInst, uinteger.Parse(El.ToString())) = DimCalendarLevel.dclDay Then
Result := CalendarDimension.Day(DimInst, CalendarDimension.Shift(DimInst, uinteger.Parse(El.ToString()), 365)) As Integer;
Else
Result := -1;
End If;
// Return the result
Return Result;
End Function GetLag;
Public Function Lag(T: Object): Object;
Var
cClass: CubeClassClass;
Cube: ICubeInstance;
CubeDest: ICubeInstanceDestination;
DimInsts: ICubeInstanceDimensions;
DimInst: IDimInstance;
Res: Array Of Integer;
I: Integer;
Cnt: Integer;
Begin
// Get current cube
cClass := New CubeClassClass.Create();
Cube := cClass.CurrentCube[Null];
CubeDest := Cube.Destinations.DefaultDestination;
// Find calendar dimension
DimInsts := CubeDest.Dimensions;
Cnt := DimInsts.Count;
For I := 0 To Cnt - 1 Do
If DimInsts.Item[I].Dimension.IsCalendar Then
DimInst := DimInsts.Item[I];
End If;
End For;
// Determine whether it is possible to have an array as input parameter T
If T Is Array Then
Res := T As Array Of Integer;
Cnt := Res.Length;
For I := 0 To Cnt - 1 Do
Res[I] := GetLag(DimInst, Res[I]);
End For;
// Return result
Return Res;
Else
//Return integer value
Return GetLag(DimInst, Integer.Parse(T.ToString()));
End If;
End Function Lag;
After creating a unit open the standard cube editing wizard and execute the operations:
On the Relations page add a relation named Previous Year Value, with the YEAR_BEFORE identifier and set up relation as the following custom function: [Unit identifier].Lag(T) for Fore.
On the Calculated Facts page for the Previous Year fact specify the formula Previous year value[Value] in the formula editor. After the formula is saved, it looks as follows: YEAR_BEFORE[@[1]]. In the calculated fact editing dialog box select the Calculate by Physical Data checkbox in order that the custom function handles and returns array of numeric values on relations calculation.
As a result of relation in the calculated fact formula, value for the Previous Year fact is taken from the same day of the previous year, for example:
See also: