Yaseen
10 months 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?
- 10 months 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)
- 10 months 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