Extracting Day, Month, And Year Information From Date Prompt In OBI EE

I struggled with this concept for almost a week before finally coming up with an answer.  I have to give full credit to the users of the OTN (Oracle Technology Network) for helping me through this problem.  The time and effort that I went through to solve this problem has prompted me to create a blog about it in hope of saving someone else the time.

Problem:  How to get the Day, Month and Year values returned by a Calendar prompt in OBI EE.  The reason I needed this was because the Calendar prompt will always return it's value in the format dd/mm/yyyy (eg. 01/01/2009).  This remains true even if you modify the settings in your localedefinitions.xml file.  You can change the way the Calendar prompt shows the values but the returned value will always be the same.  This still doesn't explain the actual problem.  In my case I wanted to create an AS OF DATE.  So if the user selected a date, and a period (Year, Month, Quarter), the report would change to show the appropriate columns such as YearAgo, Month Ago or QuarterAgo.  This meant that I needed to know the Year and Month of the currently selected date. 

The real problem exists not in the Calendar functionality but more in the way the YEAR and MONTH functions work.  These functions will only return a result if the date format provided is dd-MMM-yyyy (eg. 01-JAN-2009).  Casting the value to change the format from within Answers I found to be impossible (I am more than open to someone proving me wrong on this ).  So in the end the answer was to extract the Month, Year and Day information through the use of Substring.  The reason this works is because the date format from the Calendar never changes, so in theory this should work for all users regardless of area.

Solution: 

Create a prompt with a calender prompt that populates a Presentation Variable called AsOfDate

Day: substring( '@{AsOfDate}{01/01/1900}' from (locate('/','@{AsOfDate}{01/01/1900}',1) +1)for (locate('/','@{AsOfDate}{01/01/1900}' ,4) - locate('/','@{AsOfDate}{01/01/1900}',1)-1))

Month:
substring( '@{AsOfDate}{01/01/1900}' from 1 for (locate('/','@{AsOfDate}{01/01/1900}' ,1) -1))

Year: substring( '@{AsOfDate}{01/01/1900}' from (locate('/','@{AsOfDate}{01/01/1900}' ,4) +1) for 4)

I then used these values to extract the information I needed from my periods table.

In closing, if the user selects Period = Year and from the calendar they select AsOfDate=01/01/2009 my report will dynamically select the Year column, some other measure, and some other measuer a year ago where the year is less than 2009.  Hence, giving the report of Year and Year ago as of 2009.  I hope this helps.  And if anyone can show me a better or cleaner solution to this I would really be happy


 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this entry.
Comments

Leave a comment

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.