Você está na página 1de 24

Hands-On Lab

Building Your First Cube with


SQL Server 2008 R2 Analysis Services


Lab version: 1.0.0
Last updated: 7/8/2014




CONTENTS
OVERVIEW ................................................................................................................................................... 3
EXERCISE 1: DEVELOPING THE RESELLER SALES CUBE .................................................................. 4
Task 1 Creating the Analysis Services Project .................................................................................... 5
Task 2 Configuring the Analysis Services Project ............................................................................... 5
Task 3 Creating the AdventureWorksDW2008R2 Data Source ......................................................... 5
Task 4 Creating the Reseller Sales Data Source View ........................................................................ 6
Task 5 Configuring the Reseller Sales Data Source View ................................................................... 8
Task 6 Creating the Date Dimension ................................................................................................ 11
Task 7 Creating the Product Dimension ........................................................................................... 17
Task 8 Creating the Salesperson Dimension .................................................................................... 18
Task 9 Assembling the Reseller Sales Cube ...................................................................................... 21
Task 10 Browsing the Reseller Sales Cube ....................................................................................... 23
Task 11 Finishing Up ......................................................................................................................... 23
SUMMARY .................................................................................................................................................. 24


Overview
This lab will create an Analysis Services project that consists of a data source, data source view, cube
and three dimensions.
Note: Before you start with this exercise you must ensure that your machine meets the system
requirements detailed in the next section. Additionally, you must complete the setup steps described in
the next section.

Objectives
The objectives of this exercise are to:
Create and configure an Analysis Services project
Create a data source
Create a data source view
Create dimensions
Assemble and format a cube
Browse the cube

System Requirements
You must have installed the following items to complete this lab:
Microsoft SQL Server 2008 R2:
Database Engine
Analysis Services
SQL Server Business Intelligence Development Studio
SQL Server AdventureWorks2008 R2 sample databases
AdventureWorksDW2008R2

Setup
All the requisites for this lab are verified using the Configuration Wizard. To make sure that everything is
correctly configured, follow these steps.
Note: To perform the setup steps you need to run the scripts in a command window with
administrator privileges.

1. Launch the Configuration Wizard for this lab by double-clicking the Dependencies.dep file
located under the Source\Setup folder of this lab. Install any pre-requisites that are missing
(rescanning if necessary) and complete the wizard.

Cleanup
There is no need to cleanup if you intend to continue the sequence of labs in this training kit.
1. To restore the original state of the AdventureWorksDW2008R2 SQL Server database and
remove the Sales Analysis Analysis Services database, execute the Cleanup.cmd script located
under the Setup folder in the Source folder of this lab.

Exercises
This Hands-On Lab comprises the following exercise:
1. Developing the Reseller Sales Cube

Estimated time to complete this lab: 45 minutes.

Exercise 1: Developing the Reseller Sales
Cube
In this exercise, you will commence by creating and configuring an Analysis Services project. You will
then create a data source to reference the AdventureWorksDW2008R2 database. Based on this data
source, you will create and configure data source view based on the FactResellerSales and
FactSalesQuota tables, and some associated dimension tables. You will then create three dimensions:
Date, Product and Salespeople, and then use these to assemble a cube. Finally you will deploy the
project and browse the cube.

Task 1 Creating the Analysis Services Project
In this task, you will open an existing solution that consists of the completed labs. You will then add an
Analysis Services project to the solution.
1. Open SQL Server Business Intelligence Development Studio from Start | All Programs |
Microsoft SQL Server 2008 R2 | SQL Server Business Intelligence Development Studio.
2. To open the AdventureWorksBI solution, on the File menu, select Open | Project/Solution.
3. In the Open Project window, navigate to the Ex1-DevelopingTheResellerSalesCube\Begin
folder located in the Source folder for this lab, select the AdventureWorksBI.sln file, and then
click Open.
Note: This solution consists of all completed labs that precede this lab.

4. In Solution Explorer, if necessary, collapse the Populate DW and Sales Reports projects.
5. In Solution Explorer, right-click the AdventureWorksBI solution, and then select Add | New
Project.
6. In the Add New Project window, in the Project Types pane, ensure Business Intelligence
Projects is selected, and then in the Templates pane, select Analysis Services Project.
7. In the Name box, replace the text with Sales Analysis, and then click OK.
8. To save the solution, on the File menu, select Save All.

Task 2 Configuring the Analysis Services Project
In this task, you will configure the TargetServerURL property in preparation for the deployment task
later in this lab.
1. In Solution Explorer, right-click the Sales Analysis project, and then select Properties.
2. In the Sales Analysis Property Pages window, select the Deployment page, set the Server
property to <servername>, and then click OK.
Note: You will need to substitute <servername> for the name of the machine that hosts
Analysis Services.


Task 3 Creating the AdventureWorksDW2008R2 Data Source
In this task, you will create the AdventureWorksD2008R2 data source.
3. In Solution Explorer, in the Sales Analysis project, right-click the Data Sources folder, and then
select New Data Source.
4. In the Data Source Wizard, read the welcome message, and then click Next.
5. In the Select How to Define the Connection step, in the Data Connections list, select the
SqlServerTrainingKitAlias.AdventureWorksDW2008R2 connection.
Note: SQL Server Business Intelligence Studio caches previously defined connections. If this
data source is not listed, complete these steps to create it:
Click the New button.
In the Connection Manager window, in the Server Name box, type SqlServerTrainingKitAlias,
and then in the Select or Enter a Database Name dropdown list, select
AdventureWorksDW2008R2.
Click OK.

6. Click Next.
7. In the Impersonation Information step, select Use the Service Account, and then click Next.
Note: A preferred practice is to use a dedicated domain account. For simplicity you will use the
service account in this lab.

8. In the Completing the Wizard step, accept the default Data Source Name, and then click Finish.
9. To save the solution, on the File menu, select Save All.

Task 4 Creating the Reseller Sales Data Source View
In this task, you will you create the Reseller Sales data source view. The data source view is the
foundation upon which dimensions, cubes and data mining models are developed.
1. In Solution Explorer, in the Sales Analysis project, right-click the Data Source Views folder, and
then select New Data Source View.
2. In the Welcome to the Data Source View Wizard, read the welcome message, and then click
Next.
3. In the Select a Data Source step, notice that the data source you created in Task 4 is selected,
and then click Next.
4. In the Select Tables and Views step, in the Available Objects list, while pressing the Control
key, select the following eight objects.
Note: To fully display the object names you may need to expand the size of this dialog box by
dragging any of the windows corners.

Object
DimEmployee
DimProduct
DimProductCategory
DimProductSubcategory
DimSalesTerritory
FactResellerSales
FactSalesQuota
vDateFeed

5. Click the arrow to add the selected tables to the Included Objects list.

Figure 1
Adding the Objects to the Included Objects List

6. Click Next.
7. In the Completing the Wizard step, in the Name box, replace the text with Reseller Sales, and
then click Finish.
8. When the wizard completes, in Solution Explorer, notice the addition of the Reseller Sales data
source view, and that the data source view designer opens automatically.
9. To save the solution, on the File menu, select Save All.

Task 5 Configuring the Reseller Sales Data Source View
In this task, you will refine the design of the data source view. This will involve providing friendly names
for each of the tables, creating named columns to produce date keys in each fact table, establishing
relationships between the fact tables and the Date table (which is based on a view), and replacing the
Employee table with a named query that restricts the columns and rows to those relevant to
salespeople.
1. To rename the tables, in the data source view designer, in the Tables pane (located in the
bottom left corner), select the DimEmployee table, and then in the Properties window, modify
the FriendyName property to Employee.
Note: If the Properties window is not visible, on the View menu, select Properties Window.

2. Repeat this step for each table, except vDateFeed, to remove the Dim or Fact prefix.
3. For the vDateFeed table, modify the FriendlyName property to Date.
Note: The purpose of this step is to create a user-friendly data model. It is important to
configure friendly names at the data source view level so that they are consistently inherited
throughout the objects (cubes, dimension and, mining models) created upon this view.

4. To create a named calculation in the ResellerSales table, in the Tables pane, right-click the
ResellerSales table, and then select New Named Calculation.
5. In the Create Named Calculation window, in the Column Name box, type MonthKey.
6. In the Expression box, enter the following expression, and then click OK.
T-SQL
OrderDateKey / 100

Note: The ResellerSales table data is stored by month not day. This expression removes the
date portion from the OrderDateKey. For example, the OrderDateKey value for 1 January
2008 is 20080101. The MonthKey derived from this value is 200801. The MonthKey column
will relate to the MonthKey column in the Date table.

7. Repeat the last three steps to create a new named calculation in the SalesQuota table named
CalendarQuarterKey based on the following expression.
T-SQL
(CalendarYear * 10) + CalendarQuarter

Note: The SalesQuota table data is stored at calendar quarter granularity.

8. To establish a relationship between the ResellerSales table and the Date table, in the Tables
pane, expand the ResellerSales table, right-click the MonthKey column (located at the end of
the column list), and then select New Relationship.
9. In the Specify Relationship window, in the Destination Table dropdown list, select Date.
10. In the Destination Columns column, ensure that MonthKey is selected, and then click OK.

Figure 2
Creating the ResellerSales to Date Table Relationship

11. Repeat the last three steps to create a relationship between the SalesQuota tables
CalendarQuarterKey column and the Date tables CalendarQuarterKey column.
12. To delete the relationship between the ResellerSales table and the SalesTerritory table, in the
Tables pane, in the ResellersSales table, expand the Relationships folder (located at the end of
the column list), right-click the SalesTerritory relationship, and then select Delete Relationship.
13. When prompted to delete the relationship, click OK.
Note: The relationship between the ResellerSales and SalesTerritory tables is valid, but is not
required in this project.

14. To replace the Employee table with a named query, in the Tables pane, right-click the
Employee table, and then select Replace Table | With New Named Query.
15. In the Create Named Query window, in the Name box, replace the text with Salesperson.
16. In the lower pane, replace the query text with the following.
Note: The query required in the following step may be copied from the Assets\Snippets.txt file
in the Source folder of this lab.

T-SQL
SELECT EmployeeKey, SalesTerritoryKey,
LastName + N', ' + FirstName AS SalespersonName, EmailAddress, Phone
FROM dbo.DimEmployee
WHERE SalesPersonFlag=1;

17. On the toolbar, click the Run button, and verify that 17 rows are returned.

Figure 3
Executing the Salesperson Query

18. Click OK.
19. In the data source view designer, to arrange the tables, right-click in a blank area of the
diagram, and then select Arrange Tables.
Note: To facilitate exploring the data source view diagram, click on the four-headed arrow
located in the bottom right corner. While continuing to hold the click, drag about the
thumbnail view to navigate across the diagram.


Figure 4
Navigating the Data Source View Diagram

20. To explore the data in the Salesperson table, in the Tables pane (or the diagram), right-click the
Salesperson table, and then select Explore Data.
21. Notice the four tabs in the window that allow exploring data in Table, PivotTable, Chart and
PivotChart views.
Note: It is also possible to click column headers to sort the rows by that column order,
ascending or descending.

22. To close the explorer window, on the File menu, select Close.
23. On the File menu, click Save All.
24. To close the data source view designer, on the File menu, select Close.
25. To save the solution, on the File menu, select Save All.

Task 6 Creating the Date Dimension
In this task, you will create the Date dimension. This dimension will consist of four attributes to define
calendar date periods. To support efficient and convenient navigation, you will also define a user-
defined Calendar hierarchy to deliver drilldown and drillup paths. These paths will permit users to
summarize cube measures at different levels of granularity.
1. In Solution Explorer, in the Sales Analysis project, right-click the Dimensions folder, and then
select New Dimension.
2. In the Welcome to the Dimension Wizard, read the welcome message, and then click Next.
3. In the Select Creation Method step, ensure the Use an Existing Table option is selected, and
then click Next.
4. In the Specify Source Information step, in the Main Table dropdown list, select Date.
5. In the Name Column dropdown list, select DateLabel, and then click Next.
6. In the Select Dimension Attributes page, check the following attributes, and rename them as
follows.
Attribute Rename Attribute To
Date Key Date
Month Key Month
Calendar Quarter Key Calendar Quarter
Calendar Year Key Calendar Year


Figure 5
Selecting the Date Dimension Attributes

7. Click Next.
8. In the Completing the Wizard step, click Finish.
9. In Solution Explorer, notice the addition of the Date dimension, and that the dimension
designer opens automatically.
10. To save the solution, on the File menu, select Save All.
11. In the dimension designer, in the Data Source View pane, right-click the Date table, and then
select Explore Data.

Figure 6
Exploring the Date Data

12. Review the data and formats in each column.
Note: Pay particular attention to pairs of columns suffixed with Key and Label. The Key
columns are unique numeric representations of the date parts while the Label columns are
user-friendly formats of the date parts. During the wizard creation of this dimension you
selected attributes from the Key columns. The following steps will configure the Label columns
to provide a friendly name (NameColumn) for each member in the attribute.

13. To close the explore window, on the File menu, select Close.
14. In the Attributes pane (located on the left), select the Calendar Year attribute.

Figure 7
Selecting the Calendar Year Attribute

15. To configure the NameColumn, in the Properties window, select the NameColumn, and then
click the corresponding ellipsis.

Figure 8
Clicking the NameColumn Property Ellipsis

16. In the Name Column window, in the Source Column list, select the CalendarYearLabel column,
and then click OK.
17. Repeat the last three steps to configure the following attributes NameColumn bindings.
Attribute NameColumn Binding
Calendar Quarter CalendarQuarterLabel
Month MonthLabel

Note: The Date attributes NameColumn property was already configured during the wizard
configuration.

18. To assign properties to the dimension and attributes, in Solution Explorer, right-click the Date
dimension, and then select Add Business Intelligence.
19. In the Welcome to the Business Intelligence Wizard, read the welcome message, and then click
Next.
20. In the Choose Enhancement step, select the Define Dimension Intelligence enhancement, and
then click Next.
21. In the Define Dimension Intelligence step, in the Dimension Type dropdown list, select Time.
22. In the Dimension Attributes list, check the Year attribute type, and then in the corresponding
row in the Dimension Attribute column, select the Calendar Year attribute.
23. Repeat the last step to assign types to the following attributes, and then click Next.
Attribute Type Dimension Attribute
Quarter Calendar Quarter
Month Month
Date Date

24. In the Completing the Wizard step, review the type assignments, and then click Finish.
Note: Mapping dimension attributes to types is especially important for the Date (Time)
dimension. This metadata is required to distinguish the dimension and its attributes, and is
referred to by certain time features, for example semi-additive cube measures, and certain
MDX time functions.

25. To create a hierarchy, from the Attributes pane, drag the Calendar Year attribute into the
Hierarchies pane.

Figure 9
Creating a Hierarchy

26. To add a new level to the hierarchy, from the Attributes pane, drag the Calendar Quarter
attribute into the hierarchy, directly beneath the Calendar Year level (on top of the <New
Level> caption).
27. Repeat the last step to add the Month, and then the Date, attributes as new levels for the
hierarchy.
28. To rename the hierarchy, right-click the name of the hierarchy (named Hierarchy), and then
select Rename.
29. Modify the name of the hierarchy to Calendar, and then press Enter.
30. To rename the first level of the hierarchy, right-click the Calendar Year level, and then select
Rename.
31. Modify the name of the level to Year, and then press Enter.
32. Repeat the last two steps to rename the Calendar Quarter level to Quarter.
33. Verify that your Calendar hierarchy looks like the following.

Figure 10
Completing the Calendar Hierarchy

34. To define the attribute relationships, in the dimension designer, select the Attribute
Relationships tab.
Note: As visualized, presently the Calendar Year, Calendar Quarter and Month attributes in
this dimension are not related (except directly to the Date attribute). This is incorrect and
inefficient. With the understanding that months belong to calendar quarters, and calendar
quarters belong to years, this needs to be explicitly configured in the dimension.

35. To relate the Months attribute to the Calendar Quarter attribute, first select the Month
attribute, and then drag it on top of the Calendar Quarter attribute.
36. Repeat the last step to relate the Calendar Quarter attribute to the Calendar Year attribute.
37. Verify that your attribute relationships look like the following.

Figure 11
Configuring the Date Dimension Attribute Relationships

38. Before browsing the dimension, the project must be deployed to the server. To deploy the
project, in Solution Explorer, right-click the Sales Analysis project, and then select Deploy.
39. When deployment completes (note the status line at the bottom of the window), in the
dimension designer, select the Browser tab.
40. In the Hierarchy dropdown list, notice that the Calendar hierarchy is selected.
41. In the browser pane, browse the hierarchy membership by expanding the All member, and
children members until you have expanded to the Date level of the hierarchy.
42. In the Hierarchy dropdown list, select the Calendar Year hierarchy, and browse this hierarchy
also.
Note: Unlike the Calendar hierarchy you created in this lab, this hierarchy is shallow (i.e. it
exists of an All level and a single level beneath it which contains distinct calendar years). This
type of hierarchy is referred to as an attribute hierarchy.
The Calendar hierarchy you created is referred to as a multi-level (or user-defined) hierarchy.
It provides convenience when drilling down or drilling up to summarize cube measures at
different levels of granularity.

43. Browse each the remaining hierarchies.
44. To save the solution, on the File menu, select Save All.
45. To close the dimension designer, on the File menu, select Close.

Task 7 Creating the Product Dimension
In this task, you will create the Product dimension. The development process is very similar to the
creation of the Date dimension. To this end, the steps in this task have been abridged. If you need
guidance with this task, refer to the more detailed steps in the previous task.
1. In Solution Explorer, in the Sales Analysis project, right-click the Dimensions folder, and then
select New Dimension.
2. In the Welcome to the Dimension Wizard, click Next.
3. In the Select Creation Method step, ensure the Use an Existing Table option is selected, and
then click Next.
4. In the Specify Source Information step, in the Main Table dropdown list, select Product.
5. In the Name Column dropdown list, select the EnglishProductName column, and then click
Next.
6. In the Select Related Tables step, notice that the related tables are checked, and click Next.
Note: The Product dimension will be based on all three product tables. This is referred to as a
snowflake dimension.

7. In the Select Dimension Attributes step, check the following attributes, and rename them as
follows (if applicable).
Attribute Rename Attribute To
Product Key Product
Color (Not applicable)
Product Subcategory Key Subcategory
Product Category Key Category

8. Click Next.
9. In the Completing the Wizard step, click Finish.
10. To save the solution, on the File menu, select Save All.
11. In the dimension designer, configure the following attributes NameColumn bindings.
Attribute NameColumn Binding
Category EnglishProductCategoryName
Subcategory EnglishProductSubcategoryName

12. Assemble the appropriate attributes to create the Products hierarchy.
Note: Attribute relationships do not need to be defined because they were inferred via the
relationship between the snowflake dimension tables.

13. To deploy the project, in Solution Explorer, right-click the Sales Analysis project, and then
select Deploy.
14. When deployment completes, select the Browser tab.
15. Browse each the hierarchies available in Hierarchies dropdown list.
16. To save the solution, on the File menu, select Save All.
17. To close the dimension designer, on the File menu, select Close.

Task 8 Creating the Salesperson Dimension
In this task, you will create the Salesperson dimension. The development of this dimension is very
similar to that of the Product dimension. Different to the Product dimension, however, is that this
dimension includes two attributes, Email Address and Phone, which you will configure not to produce
hierarchies. As such, they will be available as member properties only.
1. In Solution Explorer, in the Sales Analysis project, right-click the Dimensions folder, and then
select New Dimension.
2. In the Welcome to the Dimension Wizard, click Next.
3. In the Select Creation Method page, ensure the Use an Existing Table option is selected, and
then click Next.
4. In the Specify Source Information step, in the Main Table dropdown list, select Salesperson.
5. In the Name Column dropdown list, select SalespersonName, and then click Next.
6. In the Select Related Tables step, notice that the related table is checked, and then click Next.
Note: The Salesperson dimension will be based on the Salesperson and SalesTerritory tables.

7. In the Select Dimension Attributes step, check the following attributes, and rename them as
follows (if applicable).
Attribute Rename Attribute To
Employee Key Salesperson
Email Address (Not applicable)
Phone (Not applicable)
Sales Territory Key Region
Sales Territory Group Group

8. For the Email Address and Phone attributes, uncheck the Enable Browsing checkboxes.
Note: There is no benefit to producing a hierarchy of email addresses or phone numbers.
Unchecking the Enable Browsing checkbox will ensure that a hierarchy is not produced for
these attributes. The data will otherwise be available as member properties that may then be
introduced into queries and reports.


Figure 12
Selecting the Salesperson Dimension Attributes

9. Click Next.
10. In the Completing the Wizard step, click Finish.
11. To save the solution, on the File menu, select Save All.
12. In the dimension designer, configure the following attribute NameColumn binding.
Attribute NameColumn Binding
Region SalesTerritoryRegion

13. Assemble the appropriate attributes to create the Salespeople hierarchy.

Figure 13
Completing the Salespeople Hierarchy

Note: As for the Product dimension, attribute relationships do not need to be defined because
they were inferred via the relationship between the snowflake dimension tables.

14. To deploy the project, in Solution Explorer, right-click the Sales Analysis project, and then
select Deploy.
15. When deployment completes, select the Browser tab.
16. Browse each the hierarchies available in Hierarchies dropdown list.
17. Notice the absence of the Email Address and Phone attributes that you configured not be
browsable.
18. To save the solution, on the File menu, select Save All.
19. To close the dimension designer, on the File menu, select Close.

Task 9 Assembling the Reseller Sales Cube
In this task, you will create the Reseller Sales cube by defining the measure group (fact) tables,
measures and the dimensions to add to the cube. Once the cube is created, you will format the
measures and deploy the project to the server.
1. In Solution Explorer, in the Sales Analysis project, right-click the Cubes folder, and then select
New Cube.
2. In the Welcome to the Cube Wizard, read the welcome message, and then click Next.
3. In the Select Creation Method step, ensure the Use Existing Tables option is selected, and then
click Next.
4. In the Select Measure Group Tables step, check both the ResellerSales and SalesQuota tables,
and then click Next.
5. In the Select Measures step, uncheck the top most checkbox to the left of the Measure header.

Figure 14
Unchecking All Measures

6. Check only the following measures, and then click Next.
Measure Group Measure
Reseller Sales Order Quantity
Reseller Sales Total Product Cost
Reseller Sales Sales Amount
Sales Quota Sales Amount Quota

7. In the Select Existing Dimensions step, ensure all dimensions are checked, and then click Next.
8. In the Select New Dimensions step, uncheck the top most checkbox to the left of the
Dimension header, and then click Next.
9. In the Completing the Wizard step, accept the default cube name (based on the data source
view name), and then click Finish.
10. In Solution Explorer, notice the addition of the Reseller Sales cube, and that the cube designer
opens automatically.
11. To save the solution, on the File menu, select Save All.
12. In the cube designer, to format the all measures, right-click in the blank area inside the
Measures pane (located at the upper left corner), and then select Show Measures In |Grid.
13. Select the first measure, and then while pressing the Shift key, select the last measure.
14. In the Properties window, in the FormatString property, type #,#.
Note: This will format the values with a comma for the thousands separator.

15. Right-click inside the Measures pane again, and then select Show Measures In | Tree.
16. To deploy the project, in Solution Explorer, right-click the Sales Analysis project, and then
select Deploy.

Task 10 Browsing the Reseller Sales Cube
In this task, you will use the cube browser to construct a simple query to test your cube.
1. In the cube designer, select the Browser tab (the last tab).
2. In the Metadata pane (located on the left), expand Measures, and then expand the Resellers
Sales measure group.
3. Drag the Sales Amount measure to the Drop Totals or Detail Fields Here zone of the pivot
control.
4. Expand the Sales Quota measure group, and then drag the Sales Amount Quota measure to the
right of the Sales Amount measure.
5. Expand the Date dimension, and then drag the Calendar hierarchy to the Drop Column Fields
Here zone of the pivot control.
6. To filter on a particular year, click the down arrow next to the Year header, uncheck (All), check
the CY2007 member, and then click OK.

Figure 15
Filtering on CY2007

7. On the columns, expand the CY2007 member to reveal the quarters of the year.
8. In the Metadata pane, expand the Salesperson dimension, and then drag the Salespeople
hierarchy to the Drop Row Fields Here zone of the pivot control.
9. On the rows, expand the North America member, and then expand the Northwest member to
reveal the salespeople.

Task 11 Finishing Up
In this task, you will finish up by closing all applications.
1. To close the cube designer, on the File menu, select Close.
2. In SQL Server Business Intelligence Development Studio, on the File menu, select Exit.

Summary
In this lab, you have created an Analysis Services project that consists of a data source, data source view,
cube and three dimensions. The Reseller Sales cube is a queryable object that delivers rapid ad hoc
access to data.

Você também pode gostar