Question: In a Cube View heading, how can I include the last day of the month as the time description in a page caption (e.g., display "as at 30 September 2020" instead of "September 2020“)?
Updated 2 years ago
Version 4.0Assuming that the date being shown is always the last day of the month and the client is using calendar months, it is possible to use XFBR string rule to call a function to get the number of days in the month.
Source: Office Hours 2020-01-17 Partner Enablement
Namespace OneStream.BusinessRule.DashboardStringFunction.CV_HeaderDate
Public Class MainClass
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DashboardStringFunctionArgs) As Object
Try
If args.FunctionName.Equals("GetLastDayOfMonth", StringComparison.InvariantCultureIgnoreCase) Then
' Get the current year and month from the context
Dim year As Integer = DateTime.Now.Year
Dim month As Integer = DateTime.Now.Month
' Calculate the last day of the month
Dim lastDay As DateTime = New DateTime(year, month, DateTime.DaysInMonth(year, month))
' Return the formatted string
Return "as at " & lastDay.ToString("dd MMMM yyyy")
End If
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
End Class
End Namespace
Namespace OneStream.BusinessRule.DashboardStringFunction.CV_HeaderDate
Public Class MainClass
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DashboardStringFunctionArgs) As Object
Try
If args.FunctionName.Equals("GetLastDayOfMonth", StringComparison.InvariantCultureIgnoreCase) Then
Dim inputTime As Member = brapi.Finance.Members.GetMember(si, Dimtypeid.Time, args.NameValuePairs("Param_SelectMonth"))
' Get the current year and month from the context
Dim year As Integer = BRApi.Finance.Time.GetYearFromId(si,inputTime.MemberId)
Dim month As Integer = BRApi.Finance.Time.GetPeriodNumFromId(si,inputTime.MemberId)
' Calculate the last day of the month
Dim lastDay As DateTime = New DateTime(year, month, DateTime.DaysInMonth(year, month))
' Return the formatted string
Return "as at" & lastDay.ToString("dd MMMM yyyy")
End If
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
End Class
End Namespace