melvinleng wrote:
How do i create a date dimension that rolls up to Accounting Period and then Year?
I believe i need to store the dates as a number instead of string, so that i will be able to do date comparision, etc.
One thing to be very clear on; you are not storing the dates "as" anything. Dimension elements are not data, they are metadata; that is, data which describes other data. In the case of a dates dimension, it describes what time period a particular numeric or string value refers to. Your dimension elements are like column and row headers in an Excel sheet; if you have a value in cell A1, then row "A" column "1" is simply telling you that a particular value is stored at that location. It tells you nothing about the actual value that is stored there.
Your element names are always "strings" in the sense that even if they're in numeric format, they're text. But that's in the same sense that row "A" and column "1" in Excel are strings. They don't store data, they simply tell you where data
is stored.
melvinleng wrote:
If i have source data coming in as:
2011, 2011_P01, 2011-01-01
2011, 2011_P01, 2011-01-02
2011, 2011_P01, 2011-01-03
...
How do i do the mapping or write the TI code to load these dates as numbers?
1/ Forget the mapping tab, it's rubbish.
2/ Your data source appears to be comma delimited. That's fine for this purpose.
3/ Create a new process and point it to your data source.
4/ Let it read the variables. You should have three of them.
5/ On the Variables tab, set the Variable Type to String for all of them, and the Contents Type to Other.
6/ If the dimension doesn't already exist, use DimensionCreate in the Prolog tab. Use DimensionExists in an If() function if you're not sure whether it exists. (Look under the heading "Process Control TurboIntegrator Functions" in the TM1 Reference Guide for the syntax of the If() function.)
7/ On the Metadata tab, use the following functions (refer to the TM1 Reference Guide for further information about them):
- DimensionElementInsert to add the three element types. The first two columns will be C types, the last one an N type. Don't worry about the fact that the elements may have been added by previous rows (like 2011 will have been added by the first row, and will appear again in the second; TI will ignore the command if the element already exists).
- DimensionElementComponentAdd to add the period to the year and the date to the period.
- Use DimensionSortOrder to do a ByHierarchy sort to get your elements ordered correctly.
melvinleng wrote:And then display them in a "YYYY-MM-DD" format in the cube view?
Because you're using the element name as it comes in from your source, your base element name will already be in the format YYYY-MM-DD.
melvinleng wrote:Otherwise, is there any 'best practices' regarding creating a date dimension?
Best practice is not to ask that question around these parts, pilgrim, because you'll usually start a saloon fight. Especially when the subject of whether to use one time dimension or two is raised. (You can read a thread or two about that from the FAQ thread if you're interested.)