SQL Server 2014 BI Lab 03 - video.ch9.msvideo.ch9.ms/sessions/teched/eu/2014/Labs/DBI-H328.pdf ·...

68
SQL Server 2014 BI Lab 03 Developing, Deploying and Managing a Tabular Data Model in SQL Server 2014 Jump to the Lab Overview

Transcript of SQL Server 2014 BI Lab 03 - video.ch9.msvideo.ch9.ms/sessions/teched/eu/2014/Labs/DBI-H328.pdf ·...

SQL Server 2014 BI

►Lab 03

Developing, Deploying and

Managing a Tabular Data Model in

SQL Server 2014

Jump to the Lab Overview

Page 2

© Copyright 2014 Microsoft Corporation. All rights reserved.

Terms of Use

© 2014 Microsoft Corporation. All rights reserved.

Information in this document, including URL and other Internet Web site references, is subject to change

without notice. Unless otherwise noted, the companies, organizations, products, domain names, e-mail

addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real

company, organization, product, domain name, e-mail address, logo, person, place, or event is intended

or should be inferred. Complying with all applicable copyright laws is the responsibility of the user.

Without limiting the rights under copyright, no part of this document may be reproduced, stored in or

introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical,

photocopying, recording, or otherwise), or for any purpose, without the express written permission of

Microsoft Corporation.

For more information, see Microsoft Copyright Permissions at http://www.microsoft.com/permission

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property

rights covering subject matter in this document. Except as expressly provided in any written license

agreement from Microsoft, the furnishing of this document does not give you any license to these

patents, trademarks, copyrights, or other intellectual property.

The Microsoft company name and Microsoft products mentioned herein may be either registered

trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. The

names of actual companies and products mentioned herein may be the trademarks of their respective

owners.

This document reflects current views and assumptions as of the date of development and is subject

to change. Actual and future results and trends may differ materially from any forward-looking

statements. Microsoft assumes no responsibility for errors or omissions in the materials.

THIS DOCUMENT IS FOR INFORMATIONAL AND TRAINING PURPOSES ONLY AND IS PROVIDED

"AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT

NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR

PURPOSE, AND NON-INFRINGEMENT.

Page 3

© Copyright 2014 Microsoft Corporation. All rights reserved.

Contents

TERMS OF USE ............................................................................................................................... 2

CONTENTS ..................................................................................................................................... 3

ABOUT THE AUTHOR .................................................................................................................... 5

DOCUMENT REVISIONS ................................................................................................................ 5

LAB OVERVIEW .............................................................................................................................. 6

EXERCISE 1: IMPORTING DATA AND CREATING RELATIONSHIPS .......................................... 8

Task 1 – Creating an Analysis Services Tabular Project ............................................................................................... 8

Task 2 – Importing Data from Microsoft SQL Server ................................................................................................ 10

Task 3 – Exploring the ResellerSales Data ..................................................................................................................... 18

Task 4 – Importing an Additional Table From an Existing Connection.............................................................. 19

Task 5 – Importing Data From a Data Feed .................................................................................................................. 22

Task 6 – Adding Relationships to the Date Table in Data View ............................................................................ 25

Task 7 – Exploring the Model in Diagram View .......................................................................................................... 28

EXERCISE 2: ENHANCING THE MODEL INTERFACE ................................................................. 30

Task 1 – Enhancing the Date Table .................................................................................................................................. 30

Task 2 – Enhancing the SalesTerritory Table ................................................................................................................ 34

Task 3 – Enhancing the Salesperson Table ................................................................................................................... 36

Task 4 – Enhancing the Product Table ............................................................................................................................ 37

Task 5 – Enhancing the Reseller Table ............................................................................................................................ 39

Task 6 – Enhancing the ResellerSales Table.................................................................................................................. 40

Task 7 – Enhancing the SalesQuota Table ..................................................................................................................... 41

EXERCISE 3: DEFINING MEASURES AND A KPI ........................................................................ 42

Task 1 – Adding Measures to the ResellerSales Table ............................................................................................. 42

Task 2 – Adding Measures the SalesQuota Table ...................................................................................................... 46

Task 3 – Adding a KPI to the SalesQuota Table .......................................................................................................... 47

EXERCISE 4: ANALYZING THE MODEL IN THE EXCEL CLIENT ................................................. 50

Task 1 – Exploring and Testing the Model in the Excel Client ............................................................................... 50

Page 4

© Copyright 2014 Microsoft Corporation. All rights reserved.

Task 2 – Testing the YTD Measures ................................................................................................................................. 54

Task 3 – Finishing Up ............................................................................................................................................................. 55

EXERCISE 5: DEFINING PERSPECTIVES, PARTITIONS AND A ROLE ........................................ 56

Task 1 – Defining Model Perspectives ............................................................................................................................ 56

Task 2 – Defining Partitions on the ResellerSales Table .......................................................................................... 58

Task 3 – Defining Role-Based Security ........................................................................................................................... 60

Task 4 – Finishing Up ............................................................................................................................................................. 64

EXERCISE 6: DEPLOYING AND MANAGING THE MODEL ........................................................ 65

Task 1 – Deploying the Tabular Project .......................................................................................................................... 65

Task 2 – Exploring the Deployed Database .................................................................................................................. 66

Task 3 – Finishing Up ............................................................................................................................................................. 67

SUMMARY .................................................................................................................................... 68

Page 5

© Copyright 2014 Microsoft Corporation. All rights reserved.

About the Author

This lab was designed and written by Peter Myers.

Peter Myers has worked with Microsoft database and development products since

1997. Today, he specializes in all Microsoft BI products and provides mentoring,

technical training, and education content authoring for SQL Server, Office, and

SharePoint. Peter has a broad business background supported by a bachelor’s

degree in applied economics and accounting, and he extends this with solid experience backed

by current MCSE and MCT certifications. He has been a SQL Server MVP since 2007.

Document Revisions

# Date Author Comments

0 19-OCT-2014 Peter Myers Initial release

Page 6

© Copyright 2014 Microsoft Corporation. All rights reserved.

Lab Overview

Introduction

In this lab, you will develop a tabular project based on the Adventure Works data warehouse.

Specifically, it will enable sales performance analysis and monitoring of reseller sales compared

to sales quota. You will work with the entire development lifecycle including the creation of the

Tabular Project, the importing of data from both Microsoft SQL Server and an OData data feed,

the enhancement of the data model, and the implementation of business logic with measures

and a key performance indicator (KPI). Once you have explored and tested the data model, you

will enhance it with perspectives, partitions and a security role. Finally, you will deploy the

project to a tabular instance of Analysis Services.

Note: The estimated time to complete this lab is 90 minutes, and it is possible to break down

this long lab into shorter activities, allowing you to (re)commence from any of the six exercises.

Objectives

The objectives of this exercise are to:

Create a Tabular project

Load data in the model designer

Enhance the model design with calculated columns and hierarchies

Define measures to aggregate and transform the tabular data

Explore and test the model using Excel

Define perspectives

Define and refresh table partitions

Define a security role

Deploy the project to a Tabular instance of Analysis Services

Page 7

© Copyright 2014 Microsoft Corporation. All rights reserved.

Exercises

This hands-on lab comprises the following exercise:

1. Creating the Tabular Model Project

2. Importing Data and Creating Relationships

3. Enhacing the Model Interface

4. Defining Measures and a KPI

5. Analyzing the Model in the Excel Client

6. Defining Perspectives, Partitions and a Role

7. Deploying and Managing the Model

Estimated time to complete this lab: 90 minutes

Page 8

© Copyright 2014 Microsoft Corporation. All rights reserved.

Exercise 1: Importing Data and Creating

Relationships

In this exercise, you will commence by creating an Analysis Services project. You with then

import data from two data sources. The first will be the Microsoft SQL Server

AdventureWorksDW2014 database. The second will be an intranet OData data service.

The Table Import Wizard will be used to configure the connection details, and select the tables

(and feed) to import. The interface includes the ability to select the table columns to import and

to filter rows. It is important not to include columns or rows that are not required by the model.

Including only data that is required by the model will conserve server resources and help speed

up query response times.

You will learn that the presence of foreign keys in the source data can result in the creation of

relationships in the model. When importing data from different data sources there is no way for

the Wizard to detect and create relationships, so you will create these manually.

Task 1 – Creating an Analysis Services Tabular Project

In this task, you will create an Analysis Services tabular project.

1. To open Visual Studio, on the taskbar, click the Visual Studio shortcut.

Figure 1

Selecting the Visual Studio Shortcut

2. On the File menu, select New | Project.

3. In the New Project window, in the left pane, expand Business Intelligence | Analysis

Services.

Page 9

© Copyright 2014 Microsoft Corporation. All rights reserved.

4. Select the Analysis Services Tabular Project template.

Figure 2

Selecting the Analysis Services Tabular Project Template

5. In the Name box, replace the text with Sales Analysis.

6. In the Location box, replace the text with D:\SQLServerBI\Lab03.

7. In the Solution Name box, replace the text with AdventureWorksBI, and then click OK.

8. In Solution Explorer, notice the Sales Analysis project consists of a single project item

named Model.bim. This item is the data model that you will develop in this lab.

9. Notice that the Model.bim item was automatically opened.

Note: Each tabular project consists of a single data model, and no additional data

models can be added. When deployed for the first time, the project creates a database

on the target Analysis Services instance.

Page 10

© Copyright 2014 Microsoft Corporation. All rights reserved.

10. To save the project, on the File menu, select Save All.

Note: It is a good practice to regularly save the solution to protect your development

effort in case of an unexpected application crash.

The Save All function is also available from the toolbar.

Figure 3

Identifying the Save All Toolbar Button

Task 2 – Importing Data from Microsoft SQL Server

1. To launch the Table Import Wizard, on the Model menu, select Import From Data

Source.

Note: Most menu functions are also conveniently available on the toolbar.

2. In the Table Import Wizard window, in the Connect to a Data Source step, notice that

Microsoft SQL Server is selected, and then click Next.

3. In the Connect to a Microsoft SQL Server Database step, in the Server Name box,

enter localhost.

4. In the Database Name dropdown list, select the AdventureWorksDW2014 database.

Page 11

© Copyright 2014 Microsoft Corporation. All rights reserved.

5. In the Friendly Connection Name box, modify the text to AdventureWorksDW2014.

Figure 4

Configuring the Connection to the Microsoft SQL Server Database

6. Click Next.

7. In the Impersonation Information step, select the Service Account option, and then

click Next.

8. In the Choose How to Import the Data step, notice the default option to select from a

list of tables and views, and then click Next.

9. In the Select Tables and Views step, select the DimEmployee source table.

10. In the corresponding Friendly Name column, modify the text to Salesperson.

Figure 5

Selecting and Configuring the DimEmployee Table

11. To preview and filter the data in the DimEmployee table, click Preview & Filter.

Page 12

© Copyright 2014 Microsoft Corporation. All rights reserved.

12. In the Table Import Wizard window, to de-select all columns, uncheck the checkbox

located in the top left corner.

Figure 6

De-selecting All Columns in the DimEmployee Table

13. Select the following columns.

Column

EmployeeKey

SalesTerritoryKey

FirstName

LastName

LoginID

14. To filter the table to include only salespeople rows, scroll to the very end of the columns

to locate the SalesPersonFlag column(the sixth last column).

15. In the SalesPersonFlag column header, click the down arrow, de-select (Select All), and

then select TRUE.

Figure 7

Filtering the DimEmployee Table Rows

16. Click OK.

17. In the Table Import Wizard window, click OK.

Page 13

© Copyright 2014 Microsoft Corporation. All rights reserved.

18. To review the column selection and filter, in the DimEmployee row in the grid, click the

Applied Filters link.

19. Ensure that the details in the Filter Details window look like the following.

Figure 8

Reviewing the DimEmployee Table Filter Details

20. Click OK.

21. Select the DimProduct table, and repeat the steps used to configure the DimEmployee

table, but modify the Friendly Name column to Product, and then select the following

columns.

Column

ProductKey

ProductSubcategoryKey

EnglishProductName

Color

22. To filter the table to include only finished goods rows, in the FinishedGoodsFlag

column header (located to the left of the Color column), click the down arrow, de-select

(Select All), and then select TRUE.

Figure 9

Filtering the DimProduct Table Rows

Page 14

© Copyright 2014 Microsoft Corporation. All rights reserved.

23. Click OK.

24. In the Table Import Wizard window, click OK.

25. To review the column selection and filter, click the Applied Filters link.

26. Ensure that the details in the Filter Details window look like the following, and then click

OK.

Figure 10

Reviewing the DimProduct Table Filter Details

27. Click OK.

28. Select the DimProductCategory table, modify the Friendly Name column to

ProductCategory, and then then select the following columns.

Column

ProductCategoryKey

EnglishProductCategoryName

29. Click OK.

30. To review the column selection, click the Applied Filters link.

31. Ensure that the details in the Filter Details window look like the following.

Figure 11

Reviewing the DimProductCategory Table Filter Details

Page 15

© Copyright 2014 Microsoft Corporation. All rights reserved.

32. Click OK.

33. Select the DimProductSubcategory table, modify the Friendly Name column to

ProductSubcategory, and then select the following columns.

Column

ProductSubcategoryKey

EnglishProductSubcategoryName

ProductCategoryKey

34. Click OK.

35. To review the column selection, click the Applied Filters link.

36. Ensure that the details in the Filter Details window look like the following.

Figure 12

Reviewing the DimProductSubcategory Table Filter Details

37. Click OK.

38. Select the DimSalesTerritory table, modify the Friendly Name column to

SalesTerritory, and then select the following columns.

Column

SalesTerritoryKey

SalesTerritoryRegion

SalesTerritoryCountry

SalesTerritoryGroup

39. Click OK.

40. To review the column selection, click the Applied Filters link.

Page 16

© Copyright 2014 Microsoft Corporation. All rights reserved.

41. Ensure that the details in the Filter Details window look like the following.

Figure 13

Reviewing the DimSalesTerritory Table Filter Details

42. Click OK.

43. Select the FactResellerSales table, modify the Friendly Name column to ResellerSales,

and then select the following columns.

Column

ProductKey

OrderDateKey

ShipDateKey

ResellerKey

EmployeeKey

SalesTerritoryKey

OrderQuantity

TotalProductCost

SalesAmount

44. Click OK.

45. To review the column selection, click the Applied Filters link.

46. Ensure that the details in the Filter Details window look like the following.

Figure 14

Reviewing the FactResellerSales Table Filter Details

Page 17

© Copyright 2014 Microsoft Corporation. All rights reserved.

47. Click OK.

48. Select the FactResellerSalesQuota table, and modify the Friendly Name column to

SalesQuota (no filters will be applied to this table).

49. In the Table Import Wizard window, to create the tables and import the data, click

Finish.

50. In the Importing step, ensure that the status of each work item looks like the following.

Figure 15

Reviewing the Import Status

51. Click the Details link.

52. In the Details window, review the creation of model relationships. The Wizard has

created relationships for all foreign keys where the referenced and referencing columns

have been included in the table’s column selection.

53. Notice in particular the second last relationship created between the FactResellerSales

table’s SalesTerritoryKey column and the DimSalesTerritory table’s SalesTerritoryKey

column. This relationship is marked as inactive. Only one active path can exist, directly or

indirectly, between two tables in the model. An active relationship already exists

between the FactResellerSales and DimEmployee tables, and the DimEmployee table

has an active relationship to the DimSalesTerritory table. Active relationships are used

by default in client tools.

54. To close the Details window, click OK.

55. To close the Table Import Wizard window, click Close.

Page 18

© Copyright 2014 Microsoft Corporation. All rights reserved.

56. Notice the addition of the seven tables inside the model designer.

Figure 16

Reviewing the Model Tables

Note: All data loaded into the data model is read-only. The only way to modify the

data is to modify the source data and then either refresh an individual table or table

partition, or refresh the data source that will refresh all tables that are based on that

data source.

It is also possible to modify the table properties that allow modifying the selection of

columns and row filters.

57. Notice the Error List pane at the bottom of the user interface, and review the warning.

To close the window, click the X located in the top right corner of the window.

Note: This window opens automatically after certain designer processes. You may want

to close this window to maximize the available model designer space.

Figure 17

Closing the Error List Window

58. To save the project, on the File menu, select Save All.

Task 3 – Exploring the ResellerSales Data

In this task, you will explore the data loaded into the ResellerSales table.

1. In the model designer pane, select the ResellerSales table.

Figure 18

Selecting the ResellerSales Table

Page 19

© Copyright 2014 Microsoft Corporation. All rights reserved.

2. Notice that this table has 60,855 rows.

Figure 19

Reviewing the ResellerSales Table Row Count

3. To sort the rows by descending SalesAmount value, in the SalesAmount column

header, click the down arrow, and then select Sort Largest to Smallest.

4. To filter the data by a particular region, in the SalesTerritoryKey column header, click

the down arrow, de-select (Select All), select 1, and then click OK.

5. Notice that the filtered table has 7,872 rows.

Figure 20

Reviewing the Filtered ResellerSales Table Row Count

6. To reset the table sort, on the Column menu, select Sort | Clear Sort.

7. To remove all table filters, on the Column menu, select Clear All Filters.

Task 4 – Importing an Additional Table From an Existing Connection

In this task, you will re-open the AdventureWorksDW2014 connection to import rows retrieved

by using a query.

1. To launch the Table Import Wizard based on an existing connection, on the Model

menu, select Existing Connections.

2. In the Existing Connections window, notice that the AdventureWorksDW2014

connection is selected, and then click Open.

3. In the Table Import Wizard window, in the Choose How to Import the Data step,

select the Write a Query That Will Specify the Data to Import option, and then click

Next.

4. In the Specify a SQL Query step, in the Friendly Query Name box, modify the text to

Reseller.

5. To design a query, click Design.

Page 20

© Copyright 2014 Microsoft Corporation. All rights reserved.

6. In the Table Import Wizard window, in the Database View pane, expand the dbo |

Tables, and then expand the DimReseller table.

7. Select the following columns (in this order).

Column

ResellerKey

BusinessType

ResellerName

Figure 21

Reviewing the DimReseller Column Selection

8. Expand the DimGeography table, and then select the following columns (in this order).

Column

EnglishCountryRegionName

StateProvinceName

City

Page 21

© Copyright 2014 Microsoft Corporation. All rights reserved.

9. Ensure that the Selected Fields pane looks like the following.

Figure 22

Reviewing the Selected Fields

Note: The Auto Detect feature has automatically identified the relationship between

the two tables and will construct an appropriate join clause to relate the data in these

tables.

10. Click OK.

11. Notice the query statement that has been entered into the SQL Statement box, and

then click Finish.

12. In the Importing step, ensure that the status of each work item looks like the following.

Figure 23

Reviewing the Import Status

13. Click Close.

Page 22

© Copyright 2014 Microsoft Corporation. All rights reserved.

14. Notice the addition of the Reseller table inside the model designer.

Figure 24

Reviewing the Model Tables

Note: Relationships do not exist between the tables imported in the first import

process and the Reseller table. You will add them in a later task of this exercise.

15. To save the project, on the File menu, select Save All.

Task 5 – Importing Data From a Data Feed

In this task, you will use the Table Import Wizard to import particular date columns from the

CorporateDate data feed.

1. To launch the Table Import Wizard, on the Model menu, select Import From Data

Source.

2. In the Table Import Wizard window, in the Connect to a Data Source step, scroll to

the end of the list, and then select Other Feeds.

Figure 25

Selecting the Other Feeds Item

3. Click Next.

4. In the Connect to a Data Feed step, in the Friendly Connection Name box, modify the

text to AdventureWorks Data Service.

Page 23

© Copyright 2014 Microsoft Corporation. All rights reserved.

5. In the Data Feed URL box, enter

http://localhost:22222/AdventureWorksFeeds/DataService.svc.

Note: For convenience, the URL can be copied from the

D:\SQLServerBI\Lab03\Assets\Snippets.txt file.

6. Click Next.

7. In the Impersonation Information step, select the Service Account option, and then

click Next.

8. In the Select Tables and Views step, select the CorporateDate, table.

9. In the corresponding Friendly Name column, modify the text to Date.

Figure 26

Configuring the CorporateDate Table’s Friendly Name

10. To preview and filter the data in the CorporateDate table (feed), click Preview & Filter.

11. In the Table Import Wizard window, to de-select all columns, uncheck the checkbox

located in the top left corner.

12. Select the following columns.

Column

DateKey

Date

MonthKey

MonthLabel

CalendarQuarterLabel

CalendarYearLabel

13. Click OK.

14. To review the column selection, click the Applied Filters link.

Page 24

© Copyright 2014 Microsoft Corporation. All rights reserved.

15. Ensure that the details in the Filter Details window look like the following.

Figure 27

Reviewing the CorporateDate Table Filter Details

16. Click OK.

17. In the Table Import Wizard window, to import the data, click Finish.

18. In the Importing step, ensure that the status looks like the following.

Figure 28

Reviewing the Import Status

19. To close the Table Import Wizard window, click Close.

20. Notice the addition of the Date table inside the model designer.

Figure 29

Reviewing the Addition of the Date Table

Note: Relationships do not exist between the tables imported from the

AdventureWorksDW2014 database and the CorporateDate feed. You will add them

in the next task.

21. To save the project, on the File menu, select Save All.

Page 25

© Copyright 2014 Microsoft Corporation. All rights reserved.

Task 6 – Adding Relationships to the Date Table in Data View

In this task, you will define relationships between the ResellerSales and Date tables, and

between the ResellerSales and Reseller tables.

1. In the model designer, select the ResellerSales table.

2. In the ResellerSales table, right-click the OrderDateKey column header, and then select

Create Relationship.

3. In the Create Relationship window, configure the related lookup table and column

based on the following.

Figure 30

Configuring the OrderDateKey Relationship

4. Click Create.

5. Repeat the last three steps in this task to create a relationship between the

ShipDateKey column in ResellerSales table and the DateKey column in the Date table.

6. Right-click the ResellerKey column header, and then select Create Relationship.

Page 26

© Copyright 2014 Microsoft Corporation. All rights reserved.

7. In the Create Relationship window, configure the related lookup table and column

based on the following.

Figure 31

Configuring the ResellerKey Relationship

8. Click Create.

9. To review the data model relationships, on the Table menu, select Manage

Relationships.

10. In the Manage Relationships window, notice the two relationships from the

ResellerSales table to the Date table.

Page 27

© Copyright 2014 Microsoft Corporation. All rights reserved.

11. Notice that the second relationship to the Date table you created is marked as inactive.

Figure 32

Reviewing the Model Relationships

Note: Recall that only one active path can exist between two tables. The first

relationship you created is automatically configured to be active. The second, and any

subsequently created relationships, will be configured to be inactive. You can use the

Manage Relationships window or the Diagram View to edit relationships and change

their active status.

12. Click Close.

13. To save the project, on the File menu, select Save All.

Page 28

© Copyright 2014 Microsoft Corporation. All rights reserved.

Task 7 – Exploring the Model in Diagram View

In this task, you will explore the model tables in Diagram View and define a relationship between

the SalesQuota and Date tables.

1. To switch the model view to Diagram View, in the bottom right corner of the designer,

click the Diagram View icon. You can also switch to Diagram View from the Model

menu, Model View | Diagram View.

Figure 33

Switching to Diagram View

Note: Diagram View is a useful way to visualize the model’s tables and relationships.

Beyond the model visualization, this view exposes useful functionality to enhance the

design of the data model. Oftentimes this functionality is available in Data View (the

default view consisting of the tables and rows).

Calculated columns and measures can only be defined in Data View, and hierarchies

can only be defined in Diagram View.

When appropriate, you can choose to work in the view that is most productive for you.

2. Notice the options at the top of the designer window to allow the developer to select a

perspective (to be covered later), to reset the table layout (auto arrange), filter the

display of different model objects (columns, hierarchies, measures and KPIs), and explore

the view by navigating with the minimap, zooming.

Figure 34

Introducing the Diagram View Options

3. To navigate with the minimap, click the minimap icon (four sided arrow symbol).

Figure 35

Navigating With the Minimap

Page 29

© Copyright 2014 Microsoft Corporation. All rights reserved.

4. Drag the rectangle about the minimap to explore the diagram, and use it to help locate

the Date table.

5. To close the minimap, click the minimap icon again.

6. To reposition the Date table, select and drag the table so it is near the SalesQuota

table.

Note: While it is possible to right-click a table’s column to launch the same Create

Relationship window (used earlier in this exercise), it is also possible to drag a column

to another table’s column to create a relationship. Always drag from the “many” side to

the “one” side.

7. Drag the SalesQuota table’s DateKey column to the Date table’s DateKey column.

8. To rearrange the tables in the diagram, click Reset Layout.

9. When prompted to reset the layout, click Reset Layout.

10. To save the project, on the File menu, select Save All.

Page 30

© Copyright 2014 Microsoft Corporation. All rights reserved.

Exercise 2: Enhancing the Model Interface

In this exercise, you will enhance the data model interface to better support end user

exploration and querying.

To produce an enhanced data model, for each table, and as appropriate, you will rename

columns, create calculated columns based on expressions, create hierarchies to support the

ability to drill down and drill up to analyze data at different levels of granularity, and hide

columns.

Note: To commence the lab starting from this exercise, in Visual Studio, open the

AdventureWorksBI.sln file from the D:\SQLServerBI\Lab03\Starter\Ex02 folder, and then

from Solution Explorer, open the Model.bim file.

Task 1 – Enhancing the Date Table

In this task, you will enhance the Date table with a Calendar hierarchy.

1. To switch the model view to Grid View for the Date table, right-click the Date table

header, and then select Go To.

2. To mark the table as a date table, on the Table menu, select Date | Mark As Date

Table.

3. In the Mark As Date Table window, in the Date dropdown list, notice that the Date

column is selected, and then click OK.

Note: Marking a date table will help client applications understand how time is defined

in the data model. Power View is one such example that interrogates the data model

for a date table. Excel PivotTables will surface appropriate time-based filter options

based on a marked date table.

4. To rename the MonthLabel column, right-click the MonthLabel column header, and

then select Rename Column.

5. Replace the column header text with Month, and then press Enter.

6. Repeat the last two steps to rename the CalendarQuarterLabel column to Quarter, and

the CalendarYearLabel column to Year.

Page 31

© Copyright 2014 Microsoft Corporation. All rights reserved.

7. To view the Month column values, in the Month column header, click the down arrow,

and then review the distinct values, available for filtering, found in the column.

Figure 36

Reviewing the Month Column Values

8. Notice that the months are sorted alphabetically, and then click Cancel.

9. To configure the months to sort chronologically in client tools, select the Month

column, and then on the Column menu, select Sort | Sort by Column.

10. In the Sort by Column window, in the second dropdown list, select the MonthKey

column.

Figure 37

Configuring the Month Column Sort Order

11. Click OK.

Page 32

© Copyright 2014 Microsoft Corporation. All rights reserved.

12. In the Month column, review the distinct values found in the column, and notice that

they are now sorted chronologically.

Figure 38

Reviewing the Month Column Sort Order

13. Switch to Diagram View.

14. Locate the Date table, hover over the top right corner of the table, and then click the

Maximize button.

Figure 39

Maximizing the Date Table

Note: Maximizing the table is a very convenient way to view its definition and to

configure it.

Page 33

© Copyright 2014 Microsoft Corporation. All rights reserved.

15. In the Date table, to create a hierarchy, in the top right corner, click Create Hierarchy.

Figure 40

Creating a Hierarchy

16. When the hierarchy is added to the table, replace the default name with Calendar, and

then press Enter.

17. To add the Year column as the first level of the hierarchy, select and then drag the Year

column on top of the Calendar hierarchy.

18. To add an additional lower hierarchy level, drag the Quarter column and drop it

beneath the Year level.

19. Repeat the last step to add the Month column as the third hierarchy level.

Figure 41

Reviewing the Calendar Hierarchy

20. To hide all columns, select the DateKey column, and then while pressing the Shift key,

select the Year column.

21. Right-click the selected columns, and then select Hide From Client Tools.

Note: Users exploring and querying this data model do not need to access the columns

directly. Year, quarter and month members are now available from the Calendar

hierarchy which is now the only visible object in this table.

Page 34

© Copyright 2014 Microsoft Corporation. All rights reserved.

22. Ensure that the Date table looks like the following.

Figure 42

Reviewing the Date Table

23. To minimize the table, in the top right corner, click Restore.

Figure 43

Restoring the Date Table

Task 2 – Enhancing the SalesTerritory Table

In this task, you will enhance the SalesTerritory table with a Regions hierarchy.

1. Locate and maximize the SalesTerritory table.

2. Right-click the SalesTerritoryRegion column, and then select Rename.

3. Rename the column to Region.

4. Repeat the last two steps to rename the SalesTerritoryCountry column to Country, and

the SalesTerritoryGroup column to Group.

Page 35

© Copyright 2014 Microsoft Corporation. All rights reserved.

5. As an alternate way to create a hierarchy, right-click the Group column, and then select

Create Hierarchy.

Note: The selected column, Group, will become the first level in the new hierarchy.

6. Replace the default hierarchy name with Regions, and then press Enter.

7. To add the next level to the Region hierarchy, right-click the Country column, and then

select Add to Hierarchy | Regions.

8. Repeat the last step to add the Region column to the hierarchy.

9. To hide all columns, select the SalesTerritoryKey column, and then while pressing the

Shift key, select the Group column.

10. Right-click the selected columns, and then select Hide From Client Tools.

11. Ensure that the SalesTerritory table looks like the following.

Figure 44

Reviewing the SalesTerritory Table

12. Minimize the SalesTerritory table.

Page 36

© Copyright 2014 Microsoft Corporation. All rights reserved.

Task 3 – Enhancing the Salesperson Table

In this task, you will enhance the Salesperson table with a calculated column to display the

salesperson’s full name.

1. Right-click the header of the Salesperson table, and then select Go To.

2. To create a column, in the column named Add Column, select any cell.

Figure 45

Adding a Calculated Column

3. In the formula bar, enter the following expression in the selected cell, and then press

Enter.

DAX

=[FirstName] & " " & [LastName]

Note: To inject the column references into the expression, when you are ready to enter

the column name, simply click anywhere in the column.

Figure 46

Reviewing the Calculated Column Expression

4. To rename the new column, right-click the CalculatedColumn1 column, and then select

Rename Column.

5. Modify the column name to Salesperson, and then press Enter.

6. To hide a range of columns, select the EmployeeKey column, and then while pressing

the Shift key, select the LoginID column.

7. Right-click the selected columns, and then select Hide From Client Tools.

8. Switch to Diagram View.

Page 37

© Copyright 2014 Microsoft Corporation. All rights reserved.

9. Ensure that the Salesperson table looks like the following.

Figure 47

Reviewing the Salesperson Table

Task 4 – Enhancing the Product Table

In this task, you will enhance the Product table with calculated columns to introduce the related

Subcategory and Category columns. You will then create the Products hierarchy.

1. Right-click the header of the Product table, and then select Go To.

2. Rename the EnglishProductName column to Product.

3. Use the steps in the previous task to add a new column based on the following

expression.

DAX

=RELATED(ProductSubcategory[EnglishProductSubcategoryName])

Note: This expression navigates the relationship to the ProductSubcategory table to

retrieve the EnglishProductSubcategoryName column value.

4. Rename the new column to Subcategory.

5. Add another column based on the following expression.

DAX

=RELATED(ProductCategory[EnglishProductCategoryName])

Note: This expression navigates two relationships, first to the ProductSubcategory

table, then the ProductCategory table, to lookup the EnglishProductCategoryName

column value.

Page 38

© Copyright 2014 Microsoft Corporation. All rights reserved.

6. Rename the column to Category.

7. To hide the ProductCategory table, right-click the ProductCategory tab, and then

select Hide from Client Tools.

8. Repeat the last step to hide the ProductSubcategory table.

9. Switch to Diagram View.

10. Notice that the ProductCategory and ProductSubcategory tables are shaded,

representing that they are hidden from client tools.

11. Locate and maximize the Product table.

12. As an alternate way to create a hierarchy, select the Product column, and then while

pressing the Ctrl key, select the Subcategory and Category columns.

13. Right-click the selected columns, and then select Create Hierarchy.

14. Replace the default hierarchy name with Products, and then press Enter.

Note: A hierarchy can only add levels based on columns in the same table. This is why

you added calculated columns to introduce the related subcategory and category

values.

The behavior for the multi-select method used in this step to create a hierarchy is

slightly different from the incremental level addition methods used earlier. When using

the multi-select method, the fields will be ordered based on cardinality (the field with

fewer members will be the higher level in the hierarchy). This is to be interpreted to be

a “suggested” order of levels only since it this may not necessarily be the correct order.

15. Hide all columns from the client tools, except the Color column.

Page 39

© Copyright 2014 Microsoft Corporation. All rights reserved.

16. Ensure that the Product table looks like the following.

Figure 48

Reviewing the Product Table

17. Minimize the Product table.

Task 5 – Enhancing the Reseller Table

In this task, you will enhance the Reseller table by creating a Geography hierarchy.

1. Locate and maximize the Reseller table.

2. To rename the ResellerName column, right-click the column, and then select Rename.

3. Replace the column header text with Reseller, and then press Enter.

4. Repeat the last two steps to rename the EnglishCountryRegionName column to

Country, and the StateProvinceName column to State.

5. Create a hierarchy named Resellers based on the BusinessType and Reseller columns

(in that order).

6. Create a second hierarchy named Geography based on the Country, State, City and

Reseller columns (in that order).

7. Hide all columns from the client tools.

Page 40

© Copyright 2014 Microsoft Corporation. All rights reserved.

8. Ensure that the Reseller table looks like the following.

Figure 49

Reviewing the Reseller Table

9. Minimize the Reseller table.

Task 6 – Enhancing the ResellerSales Table

In this task, you will enhance the ResellerSales table by hiding all columns.

1. Locate the ResellerSales table.

2. Select and then hide all columns from the client tools. Be sure not to hide the table.

Note: Generally, when enhancing the design of a fact table it is common to hide the

dimension keys and measure columns, and then define explicit measures using

aggregate functions. You will do this in the next exercise.

Be aware that this design approach may not be appropriate when developing a data

model for use by Power View. Power View has the ability to create automatic measures

that deliver flexibility to the end user by allowing them to select the aggregate

function. If this flexibility is required, the columns should be left visible and no explicit

measures should be defined.

Page 41

© Copyright 2014 Microsoft Corporation. All rights reserved.

3. Ensure that the ResellerSales table looks like the following.

Figure 50

Reviewing the ResellerSales Table

Task 7 – Enhancing the SalesQuota Table

In this task, you will enhance the SalesQuota table by hiding all columns.

1. Locate the SalesQuota table.

2. Select and then hide all columns from the client tools. Be sure not to hide the table.

3. Ensure that the SalesQuota table looks like the following.

Figure 51

Reviewing the SalesQuota Table

4. To save the project, on the File menu, select Save All.

Page 42

© Copyright 2014 Microsoft Corporation. All rights reserved.

Exercise 3: Defining Measures and a KPI

In this exercise, you will add measures to the ResellerSales and SalesQuota tables, and define

the Sales Performance KPI.

Like calculated columns, measures are based on expressions. However they are evaluated within

the query context, such as the filter context of the report or PivotTable. Simple measures just

aggregate column data. However, measure expressions can also be more sophisticated to

modify and override filter context, and to perform time intelligence (e.g. YTD calculations).

KPIs are based on measures and support the ability to define an object that delivers Value, Goal

and Status metrics.

Note: To commence the lab starting from this exercise, in Visual Studio, open the

AdventureWorksBI.sln file from the D:\SQLServerBI\Lab03\Starter\Ex03 folder, and then

from Solution Explorer, open the Model.bim file.

Task 1 – Adding Measures to the ResellerSales Table

In this task, you will add and format measures to the ResellerSales table.

1. In Diagram View, right-click the header of the ResellerSales table, and then select Go

To.

2. To add a measure based on the ProductKey column, select the ProductKey column

header, and then on the Column menu, select AutoSum | DistinctCount.

3. Notice that the Measure Grid at the bottom of the table grid. You may need to make it

larger to view its content.

Note: You can right-click the table tab to show or hide the Measure Grid.

4. Notice that the Distinct Count of ProductKey measure is added.

Note: When adding a measure in this way it will be placed in the grid below the

column it is based on. Note that the location of the measure within the Measure Grid

does not matter. The column used to define the measure, or the sequence of measures

within a column, does not impact on how it is evaluated and you can move a measure

to any location of the grid without impacting the formula.

Page 43

© Copyright 2014 Microsoft Corporation. All rights reserved.

5. Select the measure, and then in the formula bar, notice the expression that defines the

measure, and notice also that the measure name followed by a colon (:) precedes the

expression.

6. In the Properties window (located at the bottom right), modify the Measure Name to

Distinct Products.

7. In the formula bar, notice the updated name that precedes the expression.

Note: You can choose to modify the measure name in either location.

Note also that measure names must be unique within the model. It is not possible to

have a measure with the same name as a column.

8. In the Properties window, modify the Format property to Whole Number, and then

modify the Show Thousand Separator property to True.

9. Widen the ProductKey column to reveal the measure name and its value, 334.

10. Filter the EmployeeKey column to filter on the value 272.

Figure 52

Filtering the ResellerSales Table

11. Click OK.

Page 44

© Copyright 2014 Microsoft Corporation. All rights reserved.

12. Notice that the value of the measure has changed to 278. The table filters can help test

the measure expressions.

Note: The true test of a measure is in a tool like an Excel PivotTable where filter context

can be set by using columns from different tables.

13. To clear the table filter, on the Column menu, select Clear All Filters.

14. To select multiple columns, select the OrderQuantity column, and then while pressing

the Shift key, select the SalesAmount column.

15. On the Column menu, select AutoSum | Sum.

16. In the Properties window, modify the first new Measure Name property to Quantity,

the Format property to Whole Number, and the Show Thousand Separator property

to True.

17. Repeat the previous step in this task to rename the other two new measures.

Source Column Measure Name

TotalProductCost Cost

SalesAmount Sales

18. To add a measure based on an expression, in the Measure Grid, select the cell beneath

the Sales measure.

19. In the formula bar, enter the following expression.

Note: For convenience, the remaining measure expressions defined in this exercise can

be copied from the D:\SQLServerBI\Lab03\Assets\Snippets.txt file.

To paste the clipboard content into the formula bar, right-click inside the formula box,

select Paste, and then press Enter.

DAX

Profit:=[Sales] - [Cost]

20. In the Properties window, format the measure as Currency.

Page 45

© Copyright 2014 Microsoft Corporation. All rights reserved.

21. Add the following measure beneath the last, and format the measure as Percentage.

DAX

Profit%:=DIVIDE([Profit], [Sales])

Note: This measure uses the DIVIDE function to calculate the ratio of the two numbers,

providing the denominator, in this case Sales, is not zero or blank.

22. Add the following measure beneath the last, and format the measure as Currency.

DAX

Sales YTD (Ordered):=TOTALYTD([Sales], 'Date'[Date])

Note: This measure uses the TOTALYTD function to calculate year-to-date sales values

based on the dates in the related Date table. Recall that there are two relationships

between the ResellerSales and Date tables. The active relationship is based on the

OrderDateKey and the inactive relationship is based on the ShipDateKey.

The active relationship is always used by default. You will create one more measure in

this table to also calculate year-to-date sales values using the ShipDateKey

relationship.

Also, when you create this measure, in the calculation area, you will see the result of

(blank). A value cannot be displayed for this measure as it must be filtered by the date

table. You will test the measure by using an Excel PivotTable in Exercise 4.

23. Add the following measure beneath the last, and format the measure as Currency.

DAX

Sales YTD (Shipped):=TOTALYTD(CALCULATE([Sales],

USERELATIONSHIP(ResellerSales[ShipDateKey], 'Date'[DateKey])), 'Date'[Date])

Note: The CALCULATE function is being used to force the evaluation of the Sales

measure in the context of the relationship between the ShipDateKey and Date table’s

DateKey column. In other words, you are specifying a formula that will navigate the

inactive relationship.

Page 46

© Copyright 2014 Microsoft Corporation. All rights reserved.

24. To review the table definition, switch to Diagram View.

25. Locate and maximize the ResellerSales table.

26. Ensure that the ResellerSales table looks like the following.

Figure 53

Reviewing the ResellerSales Table

27. Minimize the ResellerSales table.

Task 2 – Adding Measures the SalesQuota Table

In this task, you will add and format measures to the SalesQuota table.

1. Locate and right-click the SalesQuota table, and then select Go To.

2. In the Measure Grid, in any cell, add the following measure, and then format the

measure as Currency.

DAX

Quota:=IF(HASONEVALUE('Date'[Month]), CALCULATE(SUM([QuotaAmount]),

ALL('Date'[Month])) / 3, SUM([QuotaAmount]))

Page 47

© Copyright 2014 Microsoft Corporation. All rights reserved.

Note: The data in the SalesQuota table is stored at quarter granularity, and yet the

data in the ResellerSales table is stored at month granularity.

This expression is using the IF function test whether only a single month is being used

to filter the measure. If it is a single month, then the CALCULATE function is used to

evaluate the sum of the SalesAmountQuota column for all months. As the month is

only accessible by navigating the Calendar hierarchy, it is known that specific a Year

and Quarter will be in context. Essentially the CALCULATE function is returning the

value for the quarter that the month belongs to. This value is then divided by three.

This expression is only accurate if each quarter contains three months, which is the case

with the data loaded into the Date table in Exercise 1.

3. Add the following measure beneath the last, and format the measure as Currency.

DAX

Variance:=[Sales] - [Quota]

4. Add the following measure beneath the last, and format the measure as Percentage.

DAX

Variance%:=DIVIDE([Variance], [Quota])

Task 3 – Adding a KPI to the SalesQuota Table

In this task, you will add the Sales Performance KPI to the SalesQuota table.

1. Add the following measure beneath the last, and format the measure as Currency.

DAX

Sales Performance:=[Sales]

Note: This new measure is a direct reference to the Sales measure. It will become the

base measure used to create a KPI.

2. Right-click the Sales Performance measure, and then select Create KPI.

3. In the Key Performance Indicator (KPI) window, notice that the KPI base measure

(value) is based on the Sales Performance measure.

Page 48

© Copyright 2014 Microsoft Corporation. All rights reserved.

4. In the Define Target Value group, in the Measure dropdown list, select Quota.

Note: This configuration will produce a status based on the ratio of Sales over Quota.

A value of 100% or more will mean that the sales are on, or are exceeding, target. A

value less than 0% will mean that sales are not meeting target.

5. In the Define Status Thresholds boxes, modify the values to 90 and 100.

6. In the Select Icon Style gallery, select the sixth from the left.

Figure 54

Configuring the Sales Performance KPI

7. Click OK.

Page 49

© Copyright 2014 Microsoft Corporation. All rights reserved.

8. In the Measure Grid, notice the icon added to the Sales Performance measure to

denote that it has been configured as a KPI.

Figure 55

Reviewing the Sales Performance KPI

9. To review the table definition, switch to Diagram View.

10. Maximize the SalesQuota table.

11. Ensure that the SalesQuota table looks like the following.

Figure 56

Reviewing the SalesQuota Table

12. Minimize the SalesQuota table.

13. To save the project, on the File menu, select Save All.

Page 50

© Copyright 2014 Microsoft Corporation. All rights reserved.

Exercise 4: Analyzing the Model in the Excel Client

In this exercise, you will explore and test the completed model in the Excel client.

When developing a model in Visual Studio, a workspace database is created on the nominated

workspace server. When analyzing the model in Excel, a workbook connection connects to this

database.

Note: To commence the lab starting from this exercise, in Visual Studio, open the

AdventureWorksBI.sln file from the D:\SQLServerBI\Lab03\Starter\Ex04 folder, and then

from Solution Explorer, open the Model.bim file.

Task 1 – Exploring and Testing the Model in the Excel Client

In this task, you will explore and text the model in the Excel client by producing and interacting

with a PivotTable report.

1. On the Model menu, select Analyze in Excel.

2. In the Analyze in Excel window, to connect to the model using your identity, click OK.

3. When Excel opens, you may need to switch to the Excel window.

4. In the PivotTable Fields (located at the right), review the model structure consisting of

measures, KPIs, dimensions and the dimension hierarchies.

Note: This field list is the regular Excel PivotTable Field List used when connecting to

OLAP cubes. The PowerPivot experience is not available for analyzing a tabular data

model developed in Visual Studio.

Page 51

© Copyright 2014 Microsoft Corporation. All rights reserved.

5. To test the model, in the PivotTable Fields, from inside the Date dimension, drag the

Calendar hierarchy to the Filters drop zone.

Figure 57

Adding the Calendar Hierarchy to the Filters Drop Zone

6. In the Calendar report filter (cell B1), click the down arrow, expand the All | CY2013

members, and then select the CY2013 Q2 member.

Figure 58

Filtering the PivotTable

Page 52

© Copyright 2014 Microsoft Corporation. All rights reserved.

7. Click OK.

8. In the PivotTable Fields, from inside the SalesTerritory dimension, select the Regions

hierarchy to add it to the Rows drop zone.

9. In the PivotTable Fields, in this order, select the following fields.

Type Field

Measure ResellerSales | Sales

Measure SalesQuota | Quota

Measure SalesQuota | Variance

KPI KPIs | Sales Performance | Status

Measure ResellerSales | Profit%

Measure ResellerSales | Distinct Products

10. Ensure that the PivotTable Field List resembles the following.

Figure 59

Reviewing the Configuration of the PivotTable

Page 53

© Copyright 2014 Microsoft Corporation. All rights reserved.

11. The PivotTable report should look like the following.

Figure 60

Reviewing the PivotTable Report

12. To display only the North America member, right-click the North America member

(cell A6), and then select Filter | Keep Only Selected Items.

13. To expand all of the Regions hierarchy levels, right-click the North America member

(cell A4), and then select Expand/Collapse | Expand to "Region".

14. Notice that the Northwest region is critically underperforming.

15. Right-click the Northwest member (cell A10), and then select Filter | Keep Only

Selected Items.

16. To introduce the salespeople into the report, in the PivotTable Fields, from inside the

Salesperson dimension, select the Salesperson hierarchy to add it into the Rows drop

zone.

17. Ensure that your PivotTable looks like the following.

Figure 61

Reviewing the Updated PivotTable Report

18. Notice the CY2013 Q2 quarter Quota values for the three Northwest salespeople.

Page 54

© Copyright 2014 Microsoft Corporation. All rights reserved.

19. To filter at month level, in the Calendar filter (cell B1), click the down arrow, expand the

selected CY2013 Q2 member, notice the chronologically ordered months, select the

2013 Apr member, and then click OK.

20. Now notice that the month level Quota values are one third of the quarter level values.

Figure 62

Reviewing the Updated PivotTable Report

Task 2 – Testing the YTD Measures

In this task, you will create a report using the two YTD measures created in Exercise 3.

1. To create a new worksheet, click the New Sheet button.

Figure 63

Creating a New Worksheet

2. To create a new PivotTable, on the Insert ribbon tab, from inside the Tables group, click

PivotTable.

3. In the Create PivotTable window, select the Use an External Data Source option, and

then click Choose Connection.

4. In the Existing Connections window, accept the default selection (which represents the

connection to the model), and then click Open.

5. In the Create PivotTable window, click OK.

6. In the PivotTable Fields, from inside the Date dimension, drag the Calendar hierarchy

to the Rows drop zone.

7. In the PivotTable, right-click the CY2013 member (cell A4), and then select

Expand/Collapse | Expand to "Month".

Page 55

© Copyright 2014 Microsoft Corporation. All rights reserved.

8. To hide the quarter members, right-click any month member, and then select

Show/Hide Fields | Quarter.

9. In the PivotTable Fields, from inside the ResellerSales measure group, select the Sales

YTD (Ordered) and Sales YTD (Shipped) measures.

10. Notice the accumulation of sales over months, and the different values for each

measure.

Figure 64

Reviewing the PivotTable Report

Task 3 – Finishing Up

In this task, you will close the Excel client.

1. To close Excel, click the X button located at the top right corner.

2. When prompted to save the changes, click Don’t Save.

Page 56

© Copyright 2014 Microsoft Corporation. All rights reserved.

Exercise 5: Defining Perspectives, Partitions and a

Role

In this exercise, you will define perspectives, partitions and a rolePerspectives allow delivering

different versions of the data model that show/hide different fields. This is particularly useful

when a single model covers multiple subject areas. Rather than connecting to the entire model,

a user can choose to connect to a perspective and thereby be presented with a subject-specific

subset of the model. Note that perspectives are not security mechanisms.In this data model you

will create two perspectives. One to show sales related fields, and a second to show only

monitoring specific fields.By default a table is based on a single partition. However, it is possible

to create additional partitions to simplify the management and data refresh of the table.

Typically fact table partitions are based on time periods, and a clear advantage of implementing

multiple partitions is that only the current period’s partition needs to be refreshed.You will

create four partitions in the ResellerSales table for each year from 2011 to 2014.Roles grant

permissions to users, and can support row level security. In fact, an expression can be used to

evaluate which rows in a table are available to the role.

You will create a role to allow salespeople to read the model, but only allow them to see data

related to other salespeople in their own region.

Note: To commence the lab starting from this exercise, in Visual Studio, open the

AdventureWorksBI.sln file from the D:\SQLServerBI\Lab03\Starter\Ex05 folder, and then

from Solution Explorer, open the Model.bim file.

Task 1 – Defining Model Perspectives

In this task, you will define two model perspectives, namely Sales and Monitoring.

1. In Visual Studio, on the Model menu, select Perspectives | Create and Manage.

2. In the Perspectives window, click New Perspective.

3. In the new perspective column, replace the name with Sales, and the press Enter.

4. Collapse the Date table.

5. Select only the following six tables.

Page 57

© Copyright 2014 Microsoft Corporation. All rights reserved.

Figure 65

Defining the Sales Perspective

6. To add another perspective, click New Perspective.

7. Name the new perspective Monitoring, and then select only the following tables.

Figure 66

Defining the Monitoring Perspective

8. Click OK.

9. In Diagram View, on the toolbar, in the Select Perspective dropdown list, select

Monitoring.

Page 58

© Copyright 2014 Microsoft Corporation. All rights reserved.

10. Review the subset of tables in the diagram.

Note: You will use the Monitoring perspective in Excel to query the data model later in

this exercise.

11. Switch back to the <Default> perspective.

Task 2 – Defining Partitions on the ResellerSales Table

In this task, you will define partitions on the ResellerSales table to allow its data to be refreshed

for individual years.

1. Right-click the ResellerSales table, and then select Go To.

2. On the Table menu, select Partitions.

3. In the Partition Manager window, notice that there is one partition named

ResellerSales, and that it consists of 60,855 rows.

4. In the Partition Name box, modify the text to ResellerSales 2011.

5. In the OrderDateKey column header, click the down arrow, click Number Filters, and

then select Between.

6. In the Custom Filter window, enter the following values.

Figure 67

Configuring the Partition Filter

7. Click OK.

Note: Defining multiple partitions for a table allows the efficient removal of data from

the data model, and also allows refreshing data at partition level. There is no need to

refresh partitions, particularly historical ones, where the source data has not changed.

Typically partitions are based on time periods.

Page 59

© Copyright 2014 Microsoft Corporation. All rights reserved.

8. To add a new partition based on the existing one, click Copy.

9. In the Partition Name box, modify the text to ResellerSales 2012.

10. To switch to the query editor, click the Query Editor button (located halfway down the

right side of the window.)

Figure 68

Switching to Query Editor Mode

11. Modify the OrderDateKey values in the WHERE clause to 20120101 and 20121231,

respectively.

12. Repeat the last four steps to create two additional partitions based on the following.

Partition Name OrderDateKey From OrderDateKey To

Reseller Sales 2013 20130101 20131231

Reseller Sales 2014 20140101 20141231

13. Click OK.

14. To process the ResellerSales table, on the Model menu, select Process | Process

Partitions.

15. In the Process Partitions window, select all four partitions.

Figure 69

Configuring Process for All ResellerSales Table Partitions

16. Click OK.

Page 60

© Copyright 2014 Microsoft Corporation. All rights reserved.

17. Ensure that the status of each work item looks like the following.

Figure 70

Reviewing the Refresh Status

Note: If you add up the rows for each partition they come to 60,855 – the number

contained in the original partition.

18. Click Close.

Note: Partitions can also be managed by administrators using the Object Explorer in

SQL Server Management Studio. In addition to the ability to create partitions, delete

partitions, define the partition queries and refresh partitions, it is also possible to merge

partitions.

It is not uncommon that partitions are created, defined and managed by administrators

using SQL Server Management Studio.

19. To save the project, on the File menu, select Save All.

Task 3 – Defining Role-Based Security

In this task, you will define a role to limit retrieving data for bike products only, and for the sales

territory the salesperson is assigned to.

1. To explore the salespeople data, select the Salesperson table.

2. If necessary, expand the LoginID column to view all the values in the column.

3. Notice that the salesperson Pamela Ansman-Wolfe has your login ID (used to login to

the lab machine). Also, notice that this salesperson belongs to the SalesTerritoryKey

with the value 1.

4. To navigate to the SalesTerritory table, right-click the SalesTerritoryKey column

header, and then select Navigate to Related Table.

Page 61

© Copyright 2014 Microsoft Corporation. All rights reserved.

5. Notice that the region name for the record with a SalesTerritoryKey value of 1 is

Northwest.

6. To define a model role, on the Model menu, select Roles.

7. In the Role Manager window, click New.

8. In the Name box, replace the text with Salespeople.

9. In the Permissions dropdown list, select Read.

Figure 71

Configuring the Role Permissions

10. In the Row Filters tab, in the Salesperson table row, enter the following DAX Filter

expression, and then press Enter.

Note: For convenience, the expressions defined in this exercise can be copied from the

D:\SQLServerBI\Lab03\Assets\Snippets\Snippets.txt file.

DAX

=[SalesTerritoryKey] = LOOKUPVALUE(Salesperson[SalesTerritoryKey],

Salesperson[LoginID], USERNAME())

Note: This expression uses the LOOKUPVALUE function to retrieve the

SalesTerritoryKey value for the current user. This way the role will allow salespeople to

see data related to other salespeople within their own region. This is a dynamic filter.

Page 62

© Copyright 2014 Microsoft Corporation. All rights reserved.

11. In the Row Filters tab, in the Product table row, enter the following expression, and

then press Enter.

DAX

=Product[Category] = "Bikes"

Note: This expression is a static filter.

12. Select the Members tab.

13. Click Add.

14. In the Select Users, Service Accounts, or Groups window, click Object Types.

15. In the Object Types window, de-select any selected object, and then select the Groups

object.

Figure 72

Selecting the Object Types

16. Click OK.

17. In the Enter the Object Names to Select box, enter Salespeople.

Note: The Salespeople group is maintained by the network administrator to include all

AdventureWorks salespeople, regardless of sales territory.

18. Click OK.

Page 63

© Copyright 2014 Microsoft Corporation. All rights reserved.

19. In the Role Manager window, click OK.

20. To save the project, on the File menu, select Save All.

21. To test the role, on the Model menu, select Analyze in Excel.

22. In the Analyze in Excel window, select the Role option.

23. In the Role dropdown list, select the Salespeople role, and then click OK.

24. In the Perspective dropdown list, select the Monitoring perspective.

Figure 73

Configuring the Credentials to Use to Connect to the Model

25. Click OK.

26. When Excel opens, you may need to switch to the Excel window.

27. In the PivotTable Fields, notice there are fewer dimensions available.

28. From inside the SalesTerritory dimension, select the Regions hierarchy to add it to the

Rows drop zone.

29. Right-click the Europe member (cell A2), and then select Expand/Collapse | Expand to

"Region".

30. Right-click the France member (cell A4), and then select Show/Hide Fields | Group.

Page 64

© Copyright 2014 Microsoft Corporation. All rights reserved.

31. Repeat the last step to hide the Country level also.

Figure 74

Reviewing the PivotTable Report

32. In the PivotTable Fields, from inside the SalesQuota measure group, select the Quota

and Variance measures.

33. Notice that only values for the Northwest region are visible. This is the sales territory

that your login account is related to.

34. Notice also that the Grand Total display a visual total (i.e. not the total for all regions).

Figure 75

Reviewing the PivotTable Report

Task 4 – Finishing Up

In this task, you will close the Excel client.

1. To close Excel, click the X button located at the top right corner.

2. When prompted to save the changes, click Don’t Save.

Page 65

© Copyright 2014 Microsoft Corporation. All rights reserved.

Exercise 6: Deploying and Managing the Model

In this exercise, you will deploy the project to the server and explore the functionality supported

in SQL Server Management Studio Object Explorer to manage the database and model.

Note: To commence the lab starting from this exercise, in Visual Studio, open the

AdventureWorksBI.sln file from the D:\SQLServerBI\Lab03\Starter\Ex06 folder, and then

from Solution Explorer, open the Model.bim file.

Task 1 – Deploying the Tabular Project

In this task, you will deploy the Tabular project to Analysis Services.

1. In Visual Studio, to review the project deployment properties, in Solution Explorer,

right-click the Sales Analysis project, and then select Properties.

2. In the Sales Analysis Property Pages window, notice the Server property.

Note: The property was when the project was created in Exercise 1. The tabular

development options can be set in Tools | Options.

3. Notice that the Database property is set to the name of the project.

4. Click Cancel.

5. To deploy the project, in Solution Explorer, right-click the Sales Analysis project, and

then select Deploy.

Page 66

© Copyright 2014 Microsoft Corporation. All rights reserved.

6. In the Deploy window, ensure that the status of each work item looks like the following.

Figure 83

Reviewing the Deployment Status

Note: The database is now available for querying by the AdventureWorks salespeople.

7. Click Close.

8. To close Visual Studio, on the File menu, select Exit.

Task 2 – Exploring the Deployed Database

In this task, you will use SQL Server Management Studio to explore the deployed database.

1. To open SQL Server Management Studio, on the taskbar, click the SQL Server

Management Studio shortcut.

Figure 28

Selecting the SQL Server Management Studio Shortcut

2. In the Connect to Server window, set the Server Type dropdown list to Analysis

Services, and the Server Name text to localhost\TABULAR.

3. Click Connect.

Page 67

© Copyright 2014 Microsoft Corporation. All rights reserved.

4. In Object Explorer (located at the left), expand the Databases folder.

5. Expand the Sales Analysis database folder, and then expand each of the child folders.

Figure 84

Exploring the Sales Analysis Database Objects

6. Right-click several of the connections, tables and the role to learn about the functions

available to the administrator.

Note: Once the database is deployed, common tasks include backing up the database;

modifying connection settings; processing data sources, tables and partitions; creating,

deleting, and merging partitions; and, creating and managing roles to grant

permissions to users.

The data sources, tables and table partitions can be processed according to a recurring

schedule by creating a SQL Server Agent job.

Task 3 – Finishing Up

In this task, you will close SQL Server Management Studio.

1. To close SQL Server Management Studio, on the File menu, select Exit.

Page 68

© Copyright 2014 Microsoft Corporation. All rights reserved.

Summary

In this lab, you have developed a tabular BI Semantic Model based on the

AdventureWorksDW2014 sample database to support the sales analysis of the reseller sales

against sales quota.

You worked with the entire development lifecycle including the creation of the project, the

importing of data from both Microsoft SQL Server and an OData data service, the enhancement

of the model, and the definition of measures and a Key Performance Indicator (KPI).