Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Multidimensional Modeling

Using SQL Server 2012 Analysis Services


SQL Server Data Tools (SSDT)
• Develop and deploy an Analysis Services Project
• Using fictitious company “Adventure Works Cycles”
(AWC)
• You will need
– Sample Data
– Sample Project Files
– Software

2
Sample Data
• Fictitious company Adventure Works Cycle
– Large, multinational manufacturing company that
produces and distributes
• Metal, composite bicycles
– Sell their products in North America, Europe and Asia
– Headquarter is in Bothell, Washington (500 workers)
– Employs regional sales team throughout its market base

3
Install Sample Data & Project Files
• Software
– SQL Server 2012 with following features:
• Database Engine
• Analysis Services
• SQL Server Data Tools (SSDT)
• SQL Server Management Studio
• Install Database (Method 1 - MDF file)
– Download the AdventureWorksDW2012_Data.mdf from
http://msftdbprodsamples.codeplex.com/releases/view/55330
– https://docs.microsoft.com/en-us/sql/samples/adventureworks-install-
configure?view=sql-server-ver16&tabs=ssms
• .mdf (SQL Server Master Database File)
– Copy the file in Data Directory of SQL Server Database Engine instance:
• C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data
– Start SQLServerManagementStudio & connect to DB
• Right click Databases -> Attach -> Add -> AdventureWorksDW2012_Data.mdf 4

• Remove the log file entry from the Database details pane. A new log file will be
created automatically.
Install Sample Data & Project Files
• Install Database (Method 2 - BAK file)
– Download the appropriate .bak file from one of links provided in the
download backup files section.
– Move the .bak file to your SQL Server backup location. This varies
depending on your installation location, instance name and version of
SQL Server. For example, the default location for a default instance of
SQL Server 2019 is:
C:\Program Files\Microsoft SQL
Server\MSSQL15.MSSQLSERVER\MSSQL\Backup.
– Open SQL Server Management Studio (SSMS) and connect to your SQL
Server.
– Right-click Databases in Object Explorer > Restore Database... to launch
the Restore Database wizard.

5
Install Sample Data & Project Files

6
Install Sample Data & Project Files
• Select Device and then select the ellipses (...) to choose a device.
• Select Add and then choose the .bak file you recently moved to the backup
location. If you moved your file to this location but you're not able to see it in
the wizard, this typically indicates a permissions issue - SQL Server or the
user signed into SQL Server does not have permission to this file in this
folder.
• Select OK to confirm your database backup selection and close the Select
backup devices window.
• Check the Files tab to confirm the Restore as location and file names match
your intended location and file names in the Restore Database wizard.
• Select OK to restore your database.

7
8
Grant Database Permissions
• Determine the Service Account under which Analysis Services runs by:
– SQL Server Configuration Manager
– check the Account (LOG ON AS) under which Analysis services is running
– usually it will be NT Service\MSSQLServerOLAPService

• In SQL Server Management Studio


– Security folder -> right-click Logins -> New Login
– General page -> Login Name field -> type NT Service\MSSQLServerOLAPService
– User Mapping page -> select checkbox next to AdventureWorksDW2012
– Role Membership should automatically include db_datareader and public
– Ok

9
Install Sample Projects (OPTIONAL)
• Download the “Analysis Services Tutorial SQL Server 2012.zip” from
– X http://msftdbprodsamples.codeplex.com/releases/view/55330 (obsolete)
– https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks-
analysis-services/adventure-works-multidimensional-tutorial-projects.zip
• Extract the compressed file, which contains the sample projects for each
week
• Open SQL Server Data Tools (SSDT) (opens up Visual Studio)
• Deploy the solution (.sln) file of the first lesson (build menu -> deploy)
• During deployment, Data will be processed (or imported) from the
AdventureWorksDW2012 on the local Database Engine instance

• Open SQL Server Management Studio


– Connect to Analysis Services
– Verify that a database named Analysis Services Tutorial is running
10
Creating an Analysis Services Project
• Designing a BI Application in SQL Server starts with:
– Creating an Analysis Services Project in SQL Server Data Tools (SSDT)
• A project is a collection of related objects
• A solution is a collection of projects
• To create a NEW Analysis Services Project
– Choose NEW Project from SSDT -> Installed Templates -> Business Intelligence -
> Analysis Services -> Analysis Services Multidimensional and Data Mining Project
– Change the ProjectName to your desired one

11
Defining a Data Source
• In SSDT -> right click Data Sources -> New Data Source
• Opens up Data Source Wizard -> Select How to Define Connection page ->
Create a Data Source based on New or Existing connection -> New
• Opens up Connection Manager -> Provider list box (Native OLE DB\SQL
Server Native Client 11.0)
• Server Name -> localhost
• Use Windows Authentication is selected
• Database name -> AdventureWorksDW2012
• Test connection

• Use Service Account for Impersonation Information


• Done

12
Defining a Data Source View
• A Data Source View is a single, unified view of the metadata from the
specified tables and views that Data Source defines
• Storing the metadata enables to work with the metadata during development
without an open connection to any underlying data source
• Steps:
– Right click Data Source Views -> New Data Source View
– Data Source View Wizard -> Select a Data Source -> Adventure Works DW 2012
-> Next
– ON Select Tables and Views Page -> Available object ->
• DimCustomers (dbo), DimDate (dbo), DimGeography (dbo), DimProduct (dbo), FactInternetSales
(dbo) -> NEXT
– Name field -> Adventure Works DW 2012
– Data Source View will appear in Solution explorer
– Content of the View will be displayed in Data Source View Designer which
contains:
• A Diagram Pane, which displays tables and their relationships
13
• A Tables Pane, which displays the tables and their schema in a tree view
• A Diagram Organizer pane, for creating subdiagrams, to view subsets of the view
Modifying Default Table Names
• Change the FriendlyName property of all the
tables to in the Properties window
– FactInternetSales -> InternetSales
– DimProduct -> Product
– DimCustomer -> Customer
– DimDate -> Date
– DimGeography -> Geography

14
Defining and deploying a Cube
• Defining a Dimension
– In the Solution Explorer in SSDT
• Right click Dimensions -> New Dimension – Next ->
• Select Creation Method (Use an existing table) -> Next ->
• Specify Source Information -> Adventure Works DW 2012
• Main table list -> Date -> Next
• Select Dimension Attributes ->
– Date Key, Full Date Alternate Key, English Month Name, Calendar
Quarter, Calendar Year, Calendar Semester
• Change the Attribute Type column value for FullDateAlternateKey
from Regular to Date (Date.Calendar.Date)
• Change EnglishMonthName to Month (Date.Calendar.Month)
• CalenderQuarter to Quarter
15
• CalenderYear to Year
• CalendarSemester to Half Year
• NEXT -> Finish
Defining a Cube
• In the Solution Explorer in SSDT
– Right click Cubes -> New Cube – Next ->
– Select Creation Method (Use an existing table) -> Next ->
– Select Measure Group Tables -> Adventure Works DW 2012 ->
– Click Suggest, to let the wizard suggest table to create measures -> Next
(It suggested internetSales)
– On Select Measures -> uncheck the following measures:
• Promotion Key, Currency Key, Sales Territory Key, Revision Number

– Next
– Select existing Dimension page -> Date -> Next
– Select New Dimensions page -> select Customer,
Geography and Product,
– uncheck the Fact InternetSales checkbox 16

– Next -> Cube Name -> Analysis Services Tutorial


Adding Attributes to Dimensions
• Populate Dimension with attributes that represent each data element in the
dimension
• Attributes are commonly based on fields from a data source view
• Fields from any table in Data Source View can be added as attribute
• Steps of adding Attributes to Customer & Product Dimension:
– Double click the Customer Dimension in the Dimensions node of Solution Explorer
– Drag the following columns from the Customer table in the Data Source View pane to the
Attributes Pane:
• BirthDate, MaritalStatus, Gender, EmailAddress, YearlyIncome, TotalChildren, NumberChildrenAtHome,
EnglishEducation, EnglishOccupation, HouseOwnerFlag, NumberCarsOwned, Phone, DateFirstPurchase,
CommuteDistance
– Drag the following columns from the Geography table in the Data Source View to the
Attributes Pane:
• City, StateProvinceName, EnglishCountryRegionName, PostalCode
– Double click the Product Dimension in the Dimensions
– Drag the following columns from the Product table in the Data Source View pane to the
Attributes pane: 17
• StandardCost, Color, SafetyStockLevel, ReorderPoint, ListPrice, Size, SizeRange, Weight, DaysToManufacture,
ProductLine, DealerPrice, Class, Style, ModelName, StartDate, EndDate, Status

• Save All
Reviewing Cube and Dimension Properties
• Steps to review the structure of Cube & Dimension properties:
– Double click the Analysis Services Tutorial Cube in the Cubes node of Solution
Explorer
– In the Measures pane, expand the InternetSales measure group to reveal the
defined measures.
• You can change the order of measures by dragging in the list
• The measure group and each measure have properties that you can edit in the properties window
– In the Dimensions pane, review the cube dimensions.
– NOTICE:
• Solution explorer displaying 3 dimensions == the Dimensions pane displaying 5 dimensions
• Cube contains more dimensions than the dimensions created in the Database
• Because “Date” database dimension is used as the basis for three separate “date-related” cube
dimensions, based on different date-related facts in the fact table.
• These date-related dimensions are called role playing dimensions
• They allow the user, dimensions the cube by three separate facts related to each product sale
– i.e., orderdate, duedate, shipdate
• By reusing a single database dimension for multiple cube dimensions, Analysis services simplifies
18
dimension management, uses less disk space, reduces overall processing time.
Deploying an Analysis Services Project (1)
• Right click the Cube and select View Designer
– In Cube Designer -> Browser tab
• Notice that the cube cannot be browsed, because it has not yet been deployed to an instance of
Analysis Services
• Currently it is just a definition of cube
• Deploying and processing a cube performs two things:
– creates the defined objects in an instance of Analysis Services and
– populates the objects with data from the underlying data sources.

• Steps of deploying the Analysis Services Project


– Right click Analysis Services Tutorial Project -> Properties
– Notice the value for Output Path property
• It specifies the location in which the XMLA deployment scripts for the project are saved when a
project is built.
• These scripts will be used to deploy the objects in the project to an instance of Analysis Services
– In the Configuration Properties in the left pane -> select Deployment
• By default, the Analysis Services Project template configures an Analysis Services project to
incrementally deploy all projects to the default instance of Analysis Services on the local computer,
19
to create an Analysis Services database with the same name as the project, and to process the
objects after deployment by using the default processing option.
– Press OK
Deploying an Analysis Services Project (2)
• In the Solution Explorer -> right click project -> click Deploy
• SQL Server Data Tools (SSDT) builds and then deploys the
project to the specified instance of Analysis Services by using
script.
• The progress of the deployment is displayed in two windows:
– Output window (View menu -> output), displays the overall progress
– Deployment Progress – Analysis Services Tutorial window, displays the
detail about each step taken during deployment
• Review the contents of both the windows to verify that the cube
was built, deployed and processed without errors.

20
Browsing the Cube
• After you deploy and process a cube and dimensions, the cube &
dimensions data are viewable on the Browser tab, in Cube & Dimension
Designer.
• Switch to Cube Designer in SSDT. Double click your cube name in cubes
node of Solution explorer
• Select the Browser tab, and then click the Reconnect icon on the toolbar of
the designer.
• For cubes, the browser tab provides two approaches for exploring data:
– Built-in MDX Query designer to build queries that returns a flattened rowset
– Excel shortcut. It opens with a PivotTable already in the worksheet and a predefined
connection to the model workspace database
– Excel generally offers a better browsing experience, because you explore cube data
interactively, using horizontal and vertical axis to analyze the relationships in your data.
– Excel also provides drilldown feature
– Practice with the browsing by adding or removing dimensions, and see how excel displays
21
PivotTable data.

You might also like