SQL Server 2008: Building a Time Dimension

In my previous post, I covered the new dimension wizard and mentioned there were options for creating time dimensions that I would cover later. Now I’ll explain those options further.


Time Dimension Options in SQL Server 2005 Analysis Services


Let’s start with a quick review of what happens in SQL Server 2005 (referred to as Yukon hereafter). On the Select the Dimension Type page of the dimension wizard, you can choose Standard, Time Dimension, and Server Time Dimension.


If you select Time Dimension, you identify the time table in your DSV and then you map your time columns to the Analysis Services time properties. For example, you map a CalendarYear column in your time table to the Year property. This association of a table column to a property helps your MDX queries how to handle time-related functions like YTD or PeriodToDate.  I admit I find this mapping process tedious, but necessary. When you use a time dimension table, you have to manage the processing of the Analysis Services dimension to add new time members if you incrementally add members to the table (instead of populating it well into the future as some people prefer to do).  The benefit of this approach is the ability to include time attributes that mean something to your industry, such as a flag for a holiday or weekend versus weekday. You also can confirm inclusion of hierarchies based on the columns you map to time properties. I never liked the inability to change the hierarchy names here, but that’s just a nit. You can, of course, add your own hierarchy or modify the hierarchy name later in the dimension editor.


If your time-related analysis is pretty simple and you don’t want to manage a time dimension in your data source, you can create a Server Time Dimension instead. This is a pretty handy feature that lets you define a date range for the dimension, the type of attributes you want to include (year, quarter, month, etc.), the calendars to support (calendar, fiscal, etc.). You can confirm the default hierarchies just like you can with a table-based time dimension. The generated dimension includes several additional attributes, such as Day of Month and Day of Year, and there are other optional attributes you can add using the editor, such as Day of Week or Trimester of Year. When you want to add the Server Time dimension to a cube, you have to add it on the Cube Structure page of the cube designer because the cube wizard doesn’t have a way for you to add it there.  You still need to ensure the end date of the range of your Server Time dimension is equal to or greater than the maximum date in your fact table.


There is a third option available. You could generate a time table by selecting the option to build the dimension without a data source. Select the Date template and you’ll get a similar interface as that for the Server Time Dimension. When you complete the dimension wizard, you have the option to generate the schema  on the spot or you can run the Schema Generation Wizard at a later time. The Schema Generation Wizard lets you create a new data source view for your time table or select an existing DSV. You can even choose to have the wizard populate the time table or you can leave it empty. You’re also given the opportunity to specify naming conventions. By the way, your credentials are used to create the database objects so you’ll need to be sure you have the correct permissions on the data source. This is a nice way to get started with a time table but you’ll need to keep it up-to-date with an ETL tool and you can’t customize it to have more or fewer columns.


Time Dimension Options in SQL Server 2008 Analysis Services


As I mentioned in my previous blog entry, SQL Server 2008 Analysis Services (which I’ll call Katmai from now on) gives you four choices for creating a dimension:


·        Use an existing table


·        Generate a time table in the data source


·        Generate a time table on the server


·        Generate a non-time table in the data source (using a template)


The second and third options relate specifically to a time dimension. If you select “Generate a time table on the server,” you get the same result as the Server Time Dimension in Yukon and an almost identical interface in the wizard. The exception is that the hierarchy confirmation page is missing in Katmai – which is fine for me as I’d rather fine-tune the hierarchy in the editor anyway.


The new option, “Generate a time table in the data source,” is the same as Yukon’s option to build the dimension from the Date template. You run the Schema Generation Wizard to design the table and optionally to populate it the first time.


So what do you do if you have a time dimension in your data source? The only option is to choose “Use an existing table.” On the Select Dimension Attributes page of the dimension wizard, which you use to select the columns from your table to include in your dimension, you have the ability to change the attribute type. This is the equivalent of mapping columns to time properties in Yukon, although I must say the interface is not ideal for this task. In short, more clicks are required to set up your time dimension from a table, but you have the benefit of getting a table and all the attributes exactly the way you want them.


Conclusion


So, functionally, nothing has really changed much for time dimensions in Katmai apart from renaming of options and some slight interface adjustments. If you base your time dimension on a table, the interface changes make the process to create the time dimension in the Analysis Services database a bit more tedious, in my opinion. Fortunately, these aren’t tasks that you have to repeat every day and, if you want to reproduce the time dimension in another cube, you can always script it out rather than build it through the wizard.  –Stacia

Other articles

Imagine feeling confident enough to handle whatever your database throws at you.

With training and consulting from SQLskills, you’ll be able to solve big problems, elevate your team’s capacity, and take control of your data career.