Leave the Visual Studio solution open for the next exercise

Một phần của tài liệu Pro SQL server 2012 BI solutions (Trang 366 - 380)

in this exercise, you added a new SSAS project to your current Bi solution. You then created a data source and a data source view within the project. in the next exercise, you will create dimensions that use both of these items.

Dimensions

As discussed in earlier chapters, dimensions describe attributes of measured values. For example, a customer’s dimension might describe the customer’s name associated with a given sales quantity—as in “Bob Smith bought 15 items.” Of course, this leads to questions like “What items?” and “When did he buy them?” From these questions, you might decide to create both a date dimension and a products dimension, which in turn may suggest new dimensions.

In the PubsBICubes project, we currently have a single measure we need to describe: SalesQuantity. The SalesQuantity attributes are an order number, order date, title, and store. Accordingly, we create a dimension for each of these descriptors.

At a minimum, each dimension should include a unique identifier and name. This typically is a dimension key and a column that contains a human-friendly name. SSAS only forces you to include the dimensional key column, but configuring a name column is recommended.

In addition to the key and name columns, you can include other columns that provide a way of aggregating measured values or clarifying their meaning. For example, in the PubsBICube project, we use title types for both purposes—clarifying a book’s type and aggregating the sales quantity for a given type of book.

The Dimension Wizard

Select Creation Method

When the wizard starts, you are presented with a welcome screen. Click Next to navigate to the Select Creation Method page. On this page, the default choice is to use an existing table in your data source view (Figure 9-35).

The second option is to generate a timetable in the data source. Selecting this option allows SSAS to generate and fill a new date table in your SQL Server data warehouse, much as we did during the ETL process. This option has some distinct advantages, the foremost of which is that you do not have to write any SQL code yourself. The downside is that the format the table is created in may not be to your liking.

Considering that this is an easy way to create a date-time table within the data warehouse, some developers create a disposable SSAS project solely for this purpose. For example, create a new SSAS project and add a New Date Time dimension using the “Generate a time table in the data source” option. Once the table is created in the data warehouse, delete the project.

Figure 9-34. Starting the Dimension Wizard

If you choose this option, the final dialog window of the wizard offers to immediately generate and run the SQL code in your data warehouse, or you can wait and perform this action at a later time.

The third option on the Dimension Wizard page is similar to the second. It generates a virtual time dimension table within the SSAS database, but not in the data warehouse. Although the table is not in the data warehouse, you still create a time dimension as if it was.

While this option is interesting, it is better to have a table in the data warehouse so that reports that work directly with the data warehouse can use it.

The fourth selection on this wizard page allows you to create one or more tables using templates. Microsoft supplies a number of templates, but you are free to create your own as well.

To create a template, make a data source view with your preferred dimension design. Then create a

dimension based on the data source view and save the resulting XML file to the proper folder, usually C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Templates\olap\1033\Dimension Templates.

As with the time table options, each template you create can be reversed engineered by Visual Studio to generate SQL code. This code can then be used to create tables within the data warehouse. With this feature, you could technically create the dimensions in Visual Studio before you created a data warehouse. But like the previous option, it is interesting but not commonly used.

The most common option used is the initial default option. Once you have selected your option, click Next to proceed to the third page of the wizard.

Figure 9-35. The first two screens of the Dimension Wizard

Figure 9-36. The Specify Source Information page in the Dimension Wizard

Specify Source Information

On the third page of the wizard, select which data source view contains the table or tables you are going to use for your dimension. In the PubsBICubes project, we have only one data source view to choose from (Figure 9-36).

After having selected the data source view, select a table from the “Main table” dropdown box. Each dimension may have only one table, which of course will be its main table. In cases where the dimension is designed in a snowflake format, such as the Titles dimension in the PubsBICubes project, the main table is the one directly connected to the fact table. This means you do not have to select both the DimTitles table and the DimPublishers tables. Only select the main DimTitles table, as shown in Figure 9-37.

Tip

■ if you want to undo a selection, highlight the errant column, open the dropdown box and click the blank area just above the column listing. in Figure 9-38, the blank area is just above the TitleKey.

Figure 9-38. Selecting the key columns for the dimension Figure 9-37. Selecting the main table for the dimension

Once you select a table, select one or more columns that define the table’s dimensional keys. Ordinarily, they are singular key columns such as the TitleKey in Figure 9-38. If you have a composite key, you can select a second column by clicking the “Add key column” option (covered by the dropdown box in Figure 9-36) after you choose the initial key column.

The last dropdown box on this page allows you to select a name column. The name column is the one that holds a label for the key column’s value. Only one column can be selected for this assignment, even if you are using a composite key.

To select a name column, access the dropdown box and select a name column (in this case it is TitleName) from the list of columns in the table (Figure 9-39). It is possible to leave them all unselected, but when a user creates a report using that dimension, they will see only ID or key values instead of human-friendly names.

Select Related Tables

Clicking the Next button advances the wizard to one of two pages: the Dimension Attributes page or the Select Related Tables page. If the only relationship line you have in the data source view is to the fact table, you will advance to the Select Dimension Attributes page. If, however, you have tables in a snowflake pattern with relationship lines connecting to other dimensional tables, you will advance to the Select Related Tables page (Figure 9-40).

In our example, The DimTitles table is connected to both the DimPublishers and DimDates tables in the data source view. Therefore, the Select Related Tables page displays both of these tables with a checked checkbox.

It is optional to include a related table; therefore, the wizard allows you to uncheck the checkbox if you feel a related table is not appropriate for the dimension you are currently building. In the case of the DimTitles table, we will leave both tables checked because they include additional information that we want to include as part of the Titles dimension.

Figure 9-39. Selecting the name column for the dimension

Figure 9-40. Selecting related tables for the dimension

Select Dimension Attributes

Dimensional tables commonly have many columns in addition to their key and name columns. In the example, we are using additional columns, such as title type, title price, and publisher name.

Each of these columns of data is copied to SSAS to form additional dimensional attributes. Remember that a dimensional attribute is a copy of data from one or more columns in a data warehouse table. For example, you may note that the TitleName does not show up in the list displayed in Figure 9-41, even though the Title Key attribute does. This is because the Title Key attribute represents both the title name and the title key columns in the data warehouse.

Later when you query the data from the SSAS dimension, you are able to specify whether the TitleKey attribute will display either the key value or the name value. From this example, you can see that a dimensional attribute is not the same as a tables column but rather a logical representation of one or more columns of data.

Keep in mind that many dimensional attributes represent only one column within the data warehouse table (that is, the key and name columns are the same). The dimension key is the most common exception, but date columns are another. For example, our DimDates table includes columns for Month and MonthName, which will form a single attribute called Month (Figure 9-41).

On the Select Dimension Attributes page, you can choose to select all or some of the available attributes.

By default, all attributes are included, but you may want to uncheck the checkbox to exclude them when the occasion calls for it. You can also change the selections, exclusions, and other options by using the dimension designer after completing the wizard.

We will configure DateName, MonthName, QuarterName, and YearName as the name columns of DateKey,

In our current example, the DimTitles table relates to both the DimPublishers table and the DimDates table to form a snowflake design within the data source view. Because of this, we see many columns available in the Select Dimensional Attributes page (Figure 9-41).

It makes sense to include some of these columns from each dimension table, but not necessarily all of them.

Including publishers names, for example, will allow for creating reports that can group titles by publishers. The same is true of the title types. But the artificial publisher key or the artificial date key (without an associated name column) is not as useful, because it is unlikely a report will benefit from either one of these columns. They have no significance outside the context of the data warehouse design.

Note

■ Your attributes may be in a different order than those in Figure 9-41. The order depends upon which table the wizard decided to select first, either the DimPublishers or the DimDates table. it may be annoying, but as long as you pay attention to which attribute you are configuring, it makes no difference.

Figure 9-41. Selecting dimensional attributes in the Dimension Wizard

Not every possible type is represented here. For example, if we try to set the TitlePrice attribute type, we find that there is no exact match within the predefined options. Most software ignores the Attribute Type setting; therefore, it has little to no impact on creating reports. Microsoft has included the setting for application programmed to use it, but leaving the selection at Regular is most often the appropriate choice.

Occasionally an attribute’s type must be more definitive. For example, the TitleId attribute in the DimTitles dimension contains data from the title_id column in the original Pubs database. Including the TitleId attribute is useful for reports that display this original Identifier. It can also be useful if you are tracking changes to dimensional attribute values over time using a Slow Changing Dimension strategy (discussed in Chapter 4).

Note

■ We discussed Slow Changing Dimensions (SCD) in Chapter 4, but we did not implement them in our

Setting Attribute Types

The wizard allows you to identify each attribute type. On the Select Dimension Attributes page, use the dropdown boxes under the Attribute Type column. All dimensional attributes are set to Regular by default. This can be left as it is.

On the occasion that you need to change the attribute type, select the row of the attribute that you want to configure. When the dropdown box appears, navigate through the dropdown treeview display until you find the appropriate type (Figure 9-42).

Figure 9-42. Setting the attribute type on a natural key column

When the dimensional attribute includes date data, the attribute type should always be configured to reflect the content. The date data determines how SSAS performs aggregations and how MDX functions are processed.

In our current example date, month, quarter, and year attributes must be configured accordingly.

Tip

■ oddly enough, the treeview has redundant type settings. in Figure 9-43 the Date dimension attribute is available in two places. Although this is confusing, it does not matter which is used to set the attribute.

After you have completed setting the attribute types, the Select Dimensional Attributes wizard page will look similar to Figure 9-44. Click Next at the bottom of this page to advance to the final page of the wizard.

Figure 9-43. Setting the attribute type on a date column

Completing the New Dimension Wizard

On the final page of the wizard, a treeview display shows the dimension composition (Figure 9-45). There is not much to do on this page other than perhaps change the name of the dimension. And since we have been removing the spaces that Visual Studio inserts between Dim and Titles, it is appropriate to do so once again on this page by changing the name to DimTitles. (We remove the spaces in the attribute names in Chapter 10, but for now, we can just leave them as is.)

Figure 9-44. The Select Dimension Attributes page after it is configured

Click Finish to close the wizard, and you will be taken to the Dimension Designer tab (Figure 9-46). In this Dimension Designer tab, you can make numerous configurations and changes to the dimension. We discuss some of these options next.

Figure 9-45. Completing the Dimension Wizard

Building the SSAS Project

Creating SSAS dimensions, data source views, and data sources all generate XML files. The format of these XML files are not compatible with SSAS. Therefore, they must be converted before uploading them to the server.

Building an SSAS project in Visual Studio combines each of the individual XML files into one master file and converts it to a compatible XMLA format. Once that is complete, it can then be uploaded to the SSAS server during deployment.

Note

■ We discuss building and deploying projects in Chapter 10. For now, we are using this feature to check for errors within the dimensions.

You can build a Visual Studio project using the build menu item (Figure 9-47). While building your project, errors in the dimension will be reported, and if errors exist, the build process will fail. You must resolve these errors and build the project once more before you can upload any of your project files to the server.

Figure 9-46. The Dimension Designer tab

As an example, let’s do something crazy like removing the TitleKey column from a dimension. When we build the PubsBICubes project, an error message displays, as shown in Figure 9-48.

Notice that in Figure 9-48, building the project displays both error and warning messages. Warning messages give you Microsoft’s recommendations on how to properly configure your dimensions. Sometimes these

recommendations can be ignored, but often they are a good idea to implement.

Tip

■ Both errors and warnings can be hidden by clicking the error and warning buttons at the top of the error list Figure 9-48. Build errors and warnings

Figure 9-47. The build menu item

in this exercise, you create the dimensions for the SSAS project. in our current design we have five dimensions to create: titles, authors, stores, dates, and orders. Let’s start with the titles dimension.

Note: if the solution from the previous exercise is closed, reopen it and remember to right-click the menu item, select Run as Administrator, and answer Yes to close the UAC.

Create the titles Dimension

Một phần của tài liệu Pro SQL server 2012 BI solutions (Trang 366 - 380)

Tải bản đầy đủ (PDF)

(823 trang)