The OneStream Community is temporarily frozen until June 29th due to the ongoing maintenance. Please read the blog post here to learn more.
Forum Discussion
fellow_Ones
2 years agoNew Contributor III
Looking for function to derive prior quarter based on the year and month value passed from parameter
Looking for function in the business rules to derive prior quarter based on the year and month value passed from parameter?
- 2 years ago
A good way to derive a time period based on a time variable is to use the TimeDimHelper class.
You can nest functions like below; to achieve most use cases.
' Declare timePeriod Dim timePeriod As String = "2024M1" ' Derive prior quarter based on time passed in Dim priorQuarterPeriod As String = TimeDimHelper.GetNameFromId(TimeDimHelper.GetQuarterIdFromId(TimeDimHelper.GetLastPeriodInPriorQuarter(TimeDimHelper.GetIdFromName(timePeriod)))) ' Log BRApi.ErrorLog.LogMessage(si, "PriorQuarter Logging: ", priorQuarterPeriod) - 2 years ago
ah! TimeDimHelper. I didn't know that existed. 🙂
However for me, I would avoid nested method calls:Dim time as string = "2022M4" Dim priorQtr as string = GetPriorQtr(time) BRApi.ErrorLog.LogMessage(si, priorQtr) ' should print 2022Q1 Public Function GetPriorQtr(time As String) As String Dim timeId As Integer = TimeDimHelper.GetIdFromName(time) Dim lastPeriodInPriorQtr As Integer = TimeDimHelper.GetLastPeriodInPriorQuarter(timeId) Dim priorQtrId As Integer = TimeDimHelper.GetQuarterIdFromId(lastPeriodInPriorQtr) Dim priorQtr As String = TimeDimHelper.GetNameFromId(priorQtrId) Return priorQtr End Function
sameburn
OneStream Employee
2 years agoA good way to derive a time period based on a time variable is to use the TimeDimHelper class.
You can nest functions like below; to achieve most use cases.
' Declare timePeriod
Dim timePeriod As String = "2024M1"
' Derive prior quarter based on time passed in
Dim priorQuarterPeriod As String = TimeDimHelper.GetNameFromId(TimeDimHelper.GetQuarterIdFromId(TimeDimHelper.GetLastPeriodInPriorQuarter(TimeDimHelper.GetIdFromName(timePeriod))))
' Log
BRApi.ErrorLog.LogMessage(si, "PriorQuarter Logging: ", priorQuarterPeriod)
- RobbSalzmann2 years agoValued Contributor II
ah! TimeDimHelper. I didn't know that existed. 🙂
However for me, I would avoid nested method calls:Dim time as string = "2022M4" Dim priorQtr as string = GetPriorQtr(time) BRApi.ErrorLog.LogMessage(si, priorQtr) ' should print 2022Q1 Public Function GetPriorQtr(time As String) As String Dim timeId As Integer = TimeDimHelper.GetIdFromName(time) Dim lastPeriodInPriorQtr As Integer = TimeDimHelper.GetLastPeriodInPriorQuarter(timeId) Dim priorQtrId As Integer = TimeDimHelper.GetQuarterIdFromId(lastPeriodInPriorQtr) Dim priorQtr As String = TimeDimHelper.GetNameFromId(priorQtrId) Return priorQtr End Function
Related Content
- 2 years ago