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.0Namespace 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