Working with Multidimensional Cubes in SQL Server -

Transcription

Working with Multidimensional Cubes in SQL Server -
Working with Multidimensional Cubes in
SQL Server -- Reporting
MIS 5346 Foundations of Data Warehousing
G. Green
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 1 of 26
Building a Multidimensional Cube
Last Updated 3.30.2015
Analyzing Cube with Reports .............................................................................. 3
Setup ................................................................................................................................................... 3
Create a Reporting Services Project using Report Designer Wizard ................................................... 3
Create reporting data source.............................................................................................................. 3
Build the Report—Example 1.............................................................................................................. 4
Refine the Report—Example 1 ........................................................................................................... 7
Build the Report—Example 2............................................................................................................ 10
Refine the Report – Example 2 ......................................................................................................... 13
Deploy the Report ............................................................................................................................. 16
View and Use the Report .................................................................................................................. 17
Distribute the Report ........................................................................................................................ 18
Build a Report Manually .................................................................................................................... 22
Portals and Dashboards .................................................................................... 25
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 2 of 26
Analyzing Cube with Reports
SQL Server Reporting Services (SSRS) is Microsoft’s enterprise report design, management, and
distribution service. It allows for the creation of both static and interactive reports. SSRS includes
several components:
 Two ways to create reports:
o Report Designer in SSDT (developer-oriented), and
o Report Builder via the web (user-oriented)
 Report Server which stores reports and makes them available to users
 Report Manager, a web-based interface for accessing and running reports stored on the server
We will use Report Designer to create reports. For the first report we will use the Report Designer
Wizard; for the second report we will use Report Designer to create report components manually.
Setup
1. To access reports via the web, right-click Internet Explorer and select Run As Administrator
(select Allow if prompted). Do this each time you need to access reports on the web.
2. In Internet Explorer, select Tools | Internet Options | Security Tab | Trusted Sites | Sites
button.
3. If you are on your own computer, add http://localhost to the list of trusted sites; if you are on a
classroom computer, add http://hsb-isy99 to the list of trusted sites. Click Add, Close, OK. You
need only do this one time.
Create a Reporting Services Project using Report Designer Wizard
1. Open the ClassPerformanceAS solution
2. File | New | Project | Business Intelligence Reporting Services template | Report Server
Project Wizard
3. Name the Project ClassPerformanceRS; choose Add to solution; OK. The report wizard should
open.
Create reporting data source
Similar to creating a cube, to create reports (and later
data mining models) you need to first tell SSAS where the
source data is. Ensure the data source name does NOT
contain spaces.
1. Name the New data source
ClassPerformanceRSDS,
2. Choose Microsoft SQL Server Analysis Services,
and click Edit…
3. Type in your server name
4. Choose the classperformanceAS database ; click
OK
5. Click the “Make this a shared data source”
checkbox; click Next
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 3 of 26
Build the Report—Example 1
Our first report will be a report of average student course grades and total course enrollments by year.
The report will default to all university courses, but also allow the user to choose specific courses to
report this information for.
1. Continuing in the wizard, click the Query Builder… button;
2. Drag/drop fields from the metadata pane to the report design area. Be sure to check the Parameter
checkbox as shown below.
3. Based on your report field/parameter selections, the wizard generates the MDX query below, which
you can change manually if desired. Click Next.
4. Select a tabular report
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 4 of 26
5. Place report fields in the appropriate areas as shown below. Note that you only get drilldown
capability if you do group by.
6. Choose a stepped table layout. Be sure to check “Include subtotals” and “Enable drilldown” boxes.
7. Choose any table style (slate is shown).
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 5 of 26
8. If you are asked to Choose the Deployment Location, set as shown below IF you are using your own
computer; if you are using the classroom computer, then for Report Server, use http://hsbisy99:80/ReportServer_MSSQLSERVERDEV, where 99 is your computer number. Click Next.
9. Name the report ClassPerformanceReport, check the Preview Report box, and click Finish.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 6 of 26
Refine the Report—Example 1
Preview the report and notice how the average course grade numbers are again off (similar to what we
observed when we first built the analysis cube):
In design view, change the default SUM for the average course grade field to AVERAGE by:
1. Double-clicking the 1st Average Coursegrade SUM field:
2. In the Value box change the word Sum to Avg. Repeat for the 2nd Average Coursegrade SUM
field.
Save and Preview the report. Notice that our report displays Grades and Enrollments by registration
date. So the Average Course Grades shown are averages per registration date.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 7 of 26
To change formatting of a report field:
1. In Design view, click the cell containing the data you want to format
to bring up its Properties.
2. We’ll be changing Average Course Grade to two decimal places by
entering “0.00” in the Format property.
As an alternative, you can right-click the cell containing the data you want to format, choose
Placeholder Properties, then select the appropriate category.
If the above two approaches do not work for the values you are formatting, you may need to do the
formatting by setting the field’s Value property. We’ll use this approach to format the dates.
3. Still in design view, highlight the [Actual_Date] value on the last row
in the report. In the Properties area, set the Value field as follows:
=FormatDateTime(Fields!Actual_Date.Value,
DateFormat.ShortDate)
This puts the date in mm/dd/yyyy format.
Note that the Average Coursegrade values could have been similarly
formatted by using the following Value in both of the
[Avg(Average_Coursegrade)] cells, in their Value properties:
=FormatNumber(Avg(Fields!Average_Coursegrade.Value),2)
4. A currency field could be formatted in the Values property as follows
(assuming the field name is Amt):
=Format(Fields!Amt.Value,"C2")
You can change the report Title and/or column headings by simply clicking inside the column headings
and renaming the columns as desired.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 8 of 26
Notice that the months in the year 2002 are in alphabetical order instead of month order. To change it:
1. Click on the Month_Of_Year row group dropdown at the bottom of the screen, and click Group
Properties…:
2. Click the Sorting category; Click in the Month_Of_Year Sort by text box, click the Delete button,
then click OK.
Preview the report.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 9 of 26
Build the Report—Example 2
Our second report will be a report of average student course grades and total course enrollments by
course. The report will also allow the user to choose courses taught by specific professors.
First, return to the Analysis Services project DSV and create a Fullname field in Dimprofessor if not
already there. Ensure the fullname field is added to the cube.
While still in the Analysis Services project, add the course Section field to the cube if not already there.
Redeploy the modified cube if necessary.
Return to the Reporting services project.
1. Create a new report by right-clicking on the Reports folder in Solution Explorer, and choose Add
New Report
2. Choose the existing shared data source (ClassPerformanceRSDS) created in Example 1; Next.
3. Click the Query Builder… button;
4. Drag/drop fields from the metadata pane to the report design area. Be sure to check the Parameter
checkbox as shown below.
Based on your report field/parameter selections, the wizard generates the MDX query below, which you
can change manually if desired.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 10 of 26
5. Select a tabular report
6. Place report fields in the appropriate areas as shown below. Note that you only get drilldown
capability if you do group by. Group by fields DON’T have to be predefined as hierarchies.
7. Choose a stepped table layout. Be sure to check “Include subtotals” and “Enable drilldown” boxes.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 11 of 26
8. Choose any table style (slate is shown).
9. If you are asked to Choose the Deployment Location, set as shown below:
10. Name the report ClassPerformanceReport2 and click Finish.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 12 of 26
Refine the Report – Example 2
Preview the report and notice how the averages are again off. They need to be corrected similar to
Example 1.
If you get a warning as in the screenshot below, it is likely because (1) SSRS wants us to create rigid
hierarchies meaning they’re pretty stable, and (2) we have Dimprof in the filter and SSRS prefers to have
hierarchies as filters.
In design view, make formatting changes similar to what was done for report 1. Namely:



Change the default for the average course grade fields from SUM to AVG
Change the Average Course Grade formats to 2 decimal positions
Rename column and report heading labels to be user friendly
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 13 of 26
Change Sum to Avg. Repeat for the all the SUM fields
.
To change formatting of a report field, right-click the field, select Text Box Properties, and change
Average Course Grade to two decimal places:
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 14 of 26
For numbers and currency, select the appropriate category then select the desired formatting type.
To change the column labels, go to Design tab, click on column heading, and change name as desired
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 15 of 26
Deploy the Report
As noted earlier, in order for reports to be accessible to users, we must deploy them to the SSRS server.
Before we can deploy the report, we need to designate the target report server.
1.
2.
3.
4.
Right-click the report server project (classperformanceRS) then choose Properties;
Set OverwriteDataSources to True.
Ensure the TargetReportFolder is ClassperformanceRS.
If you are on your own computer, set TargetServerURL to http://localhost/ReportServer. If you are
on a classroom computer, set TargetServerURL to http://hsbisy99:80/ReportServer_MSSQLSERVERDEV where 99 is your 2-digit computer number. Click OK.
5. Deploy the classperformanceRS project by rightclicking on the project in solution explorer and
choosing Deploy. If prompted, enter your windows
username and password (you may have to enter your
username as Baylor\bear_id):
If deployment is successful, you should see Output
similar to the screenshot below:
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 16 of 26
View and Use the Report
The report, once deployed, can be accessed via the web (IE or Firefox) at either:
 http://localhost/ReportServer/Pages/ReportViewer.aspx?/ClassperformanceRS/ClassPerforman
ceReport  on your own computer
-- OR - http://hsbisy99/ReportServer_MSSQLSERVERDEV/Pages/ReportViewer.aspx?/ClassperformanceRS/ClassPerfor
manceReport  on classroom computer
where ClassperformanceRS is the target report folder that you specified previously on the report project
properties page, and ClassPerformanceReport is the report (ie, rdl file) name.
The second report, once deployed, can be accessed via IE at the same URL but with Report2 at the end.
NOTE: all aspects of the URL are case-sensitive
To use the filter, select a specific course name (report 1) or professor name (report 2) and click View
Report button.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 17 of 26
Distribute the Report
Reports can be delivered to users on a regular basis via emails or posting to websites. User recipients
must have “subscriptions” to the report. To add subscriptions to a report, the data source for the report
has to be changed to run under a specific username/password. Recall that previously windows
integrated security was used for the data source.
1. In IE (running as administrator), go to report manager by entering either http://localhost/reports OR
http://hsb-isy99/reports_MSSQLSERVERDEV as appropriate.
2. Click on the Data Sources folder
3. Click on the ClassperformanceRSDS data source
4. Click the “Credentials stored securely in the report server” button
5. Supply your user name (use the format Baylor\bear_id if using classroom computer); supply your
password
6. Check the “Use as Windows credentials when connecting to the data source” box; click Apply
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 18 of 26
Ensure SQL Server Agent service started (has to be running in order to implement report subscriptions)
7. Control Panel | System and Security | Administrative Tools | Services ; start the SQL Server Agent
(MSSQLSERVER) service
After the data source security mechanism has been changed in a way that supports subscriptions, and
the SQL Server Agent service has been started, we can now specify how we want to distribute our
report. We will distribute our report by making it available on a file share.
8. While still in the Report Manager, from the Home page, click on the ClassperformanceRS link
9. Click on the dropdown of the ClassperformanceReport report. Choose Manage.
NOTE: if you’re unable to click on dropdown, make sure the http://yourcomputername/reports URL
is added to your IE’s list of compatibility view sites. See
http://stackoverflow.com/questions/15144158/can-not-open-the-drop-down-arrow-besides-thereport-in-ssrs-report-manager-to-ad.
10. Click on the Subscriptions tab
11. Click on New Subscription
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 19 of 26
12. Enter settings shown below, using your bearid and password where indicated, AND using the click
Select Schedule
13. Enter desired schedule then click OK, and OK again
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 20 of 26
14. When the report subscription is first setup, you’ll see this type of entry on the Subscriptions page:
15. After the report has run you’ll see this type of entry on the Subscriptions page (refresh the browser):
16. To access the report, go to your P drive then double-click the report file
17. To cancel the subscription, from the Subscription tab, click the Checkbox next to the subscription,
then click the Delete button:
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 21 of 26
Build a Report Manually
Let’s create a third report that is a chart. Rather than use the Report Wizard, we’ll build the report
manually. Steps below adapted from http://msdn.microsoft.com/en-us/library/cc281302.aspx
Create a report server project
1.
2.
3.
4.
5.
6.
Open SSDT. If a Report Server Project already exists, skip to the next section to Define a data source.
While in the classperformanceAS solution, on the File menu, point to New, and then click Project.
In the Project Types list, click Business Intelligence Projects.
In the Templates list, click Report Server Project.
In Name, type ClassPerformanceBarChart; Add it to the existing Solution.
Click OK to create the project.
Define a data source for the report
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Right-click the Reports folder of the ClassPerformancBarChart project;
Add…; New Item; Report. Name it ClassPerformanceBarChart.rdl; click Add
In the Report Data pane (View menu item option), click the New drop down list, and click Data Source.
In the Data Source Properties dialog box, leave the Name field as is
Verify that Embedded connection is selected.
In the Type box, select Microsoft SQL Server Analysis Services
In the connection string text box, type a valid connection string or click the Edit button to open the
Connection Properties dialog box.
In the Connection Properties dialog box, if you are on your own computer, type a period in the
Server name text box; if you are on a classroom computer, type hsb-isy99\\MSSQLSERVERDEV
In the Select or enter a database name list box, type or select classperformanceAS
Click Test Connection.
Click OK to close the Connection Properties dialog box. In the Data Source Properties dialog box you
will see the default data source name, DataSource1, and the connection string.
On the Credentials tab, ensure Use Windows Authentication is selected.
Click OK. The new data source is displayed in the Report Data pane.
Define a data set for your report including a “Filtering” Parameter
1.
2.
In the Report Data pane, right-click the data source (DataSource1) and click Add Dataset…
In the DataSet Properties dialog box, verify that Text is selected for Query type.
3. Under the Query text box, click Query Designer… button; drag student fullname, coursename,
yearmonth hierarchy, average course grade, and fact enrollment count to the report
4. In the filter area, drag the Coursename field into the Dimension Hierarchy box; set Operator to Equal;
filter to {All}, and check the Parameter box
5. Click OK then OK. The dataset fields are displayed in the Report Data pane.
Add a bar chart
1.
2.
3.
4.
5.
6.
7.
From the View menu bar item, click Toolbox.
Double-click or drag a Chart to the design surface. The Select Chart Type dialog appears.
Click Bar to display a list of bar charts. Select the first bar chart icon in the list. Close the Toolbox.
Click on the chart to bring up the chart handles. Drag the corner of the chart to increase the size of the
chart.
Click on the chart again to display the Chart Data popup. Drag and drop (or click to select) the
Fullname field in the Category Groups area.
Drag (or click to select) the Fact enrollment count and Average course grades fields from the Report
Data pane and drop them to the Values area. If you don’t see the Report Data Pane, check near the
bottom left of the screen and ensure the Report Data tab is selected.
Drag the Year field to the Series Groups area
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 22 of 26
If you have a lot of values on your category axis (ie, the Y axis), you may notice that the chart does not show
every label category on the y-axis. This is due to an automatic algorithm that calculates an interval at which to
display labels in order to prevent label collisions. If you want to display all categories on the chart, you must
specify an axis interval of 1.
Ensure all data displayed along the category axis of a bar chart
1.
2.
3.
In the Design view, right-click the y-axis and click Vertical Axis Properties.
Click the Major Tick Marks category of the Vertical Axis Properties box; change the Interval to 1.
Click OK.
Change SUMs to AVGs
If you preview the report you will notice that the Average Course Grade measure is being summed (you’re not
surprised are you!!!). Change the Average Course Grade measure from SUM to AVG.
1. In the Design view, chart data Values area, right-click in the text box that displays
Sum[Average_Course_Grade]
2. Select Series Properties
3. With the Series Data tab highlighted on the left, change Sum to Avg in the Value Field text box; OK
NOTE you will not see changes in the data until you Preview the report.
To improve the readability of the chart values, you might want to move the chart legend. In a bar chart, where
bars are shown horizontally, you can change the position of the legend so that it is above or below the chart
area. This gives more horizontal space to the bars. Also you can change the chart title and add formatting.
To display the legend below the chart area of a bar chart
1.
2.
3.
4.
5.
In Design view, right-click the legend on the chart.
Select Legend Properties.
For Legend position, select a different position. E.g., click the middle bottom option.
When the legend is placed at the top or bottom of a chart, the layout of the legend changes from
vertical to horizontal. You can select a different layout from the Layout drop-down list.
Click OK.
To change the chart title above the chart area of a bar chart
1.
2.
3.
4.
In Design view, right-click on the chart
title at the top of the chart and click Title
Properties OR double-click in the title
area.
Replace the Title text field with the
following text: Class Performance
Progress
Click anywhere outside the text.
Your report in Preview should look similar
to the example to the right.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 23 of 26
Filtering
We previously added a parameter to our report. Parameters filter rows and basically serve as a WHERE
clause in a query. The parameter you setup determines what SQL data is sent to the report. If your
parameter is initially setup to return all values for a particular column, then when the report is
displayed, the user will be able to do further filtering on that column.
Filtering is applied after the data is produced for the report and before the report is displayed. The filter
cannot be altered by the user viewing the report.
For this example we’ll filter the data by year; in particular we only want to see data for 2003.
1.
2.
3.
4.
5.
6.
7.
8.
9.
In design view, click the chart once to bring up the Chart Data
pane.
Right-click the Year field that is in the Series Groups area.
Select Series Group Properties.
Click Filters. This brings up a list of filter expressions. By default,
this list is empty.
Click Add. A new blank filter appears.
In the Expression box, type [Year]
In the Operator list box, select =
In the Value box, type 2003
Click OK then Preview modified report
Notice that the names are sorted in ascending order from bottom to top. We can change this sorting order to
descending order bottom to top. In other words, the course names will appear to be in ascending order top to
bottom.
Sort names on the bar chart
1.
2.
3.
4.
5.
6.
7.
8.
In Design view, click the chart once to bring up the Chart Data pane.
Right-click the Fullname field that is in the Category Groups area.
Select Category Group Properties.
Click the Sorting tab. This brings up a list of sort expressions. By default, this list is empty.
If there is currently no “Sort by” for Fullname, then click Add. A new sort expression appears.
In the Sort by box, select the [Fullname] expression
In the Order box, select Z to A.
Click OK then Preview. The chart shows the names in alphabetical order from top to bottom.
Changing default Axis Titles
1.
2.
3.
4.
5.
6.
Click the Axis Title on left-hand side of chart
In the Properties area, change the Caption to Students
Click the Axis Title at the bottom of chart
In the Properties area, change the Caption to Measures
Choose Axis Title Properties
Type in the new title in the Title text box.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 24 of 26
Portals and Dashboards
We’ve created several BI-related objects using several Microsoft products:
 Multidimensional data cube in SSAS
 KPIs in SSAS
 Tables and Charts in Excel
 Charts and Reports in SSRS
How do you tie all this together so that users can easily access reports and executives can easily see how
the business is performing? For accessing basic reports, it is popular to create a report portal (see
screenshots below). Portals can be designed and created with basic web-authoring tools or with tools
such as Microsoft SharePoint (described below) that specialize in creating organizational portals.
In addition to a reporting portal, we can create a dashboard that consists of a combination of
KPIs/Scorecards, Charts, and Reports/Tables that show our executives visually how the key areas of the
business are performing. There are many BI products to create executive dashboards—Microsoft has a
combination of three products (surprise, surprise!): Sharepoint, PerformancePoint, and PowerPivot.
And of course Excel can be used to create simple dashboards.
SharePoint is Microsoft’s web-based software for implementing enterprise intranets, and facilitating the
sharing of organizational documents.
PerformancePoint Services is a component of SharePoint that allows you to create dashboards in
SharePoint. From PerformancePoint, you can create new BI objects, and/or integrate BI objects that
were previously created in SSAS, SSRS, Excel (via PowerPivot) or even Visio, as well as a variety of
relational data sources. These sources would be considered PerformancePoint data sources.
PowerPivot basically makes Excel a client tool for analyzing very large analysis cubes (excel alone limits
you to 1 million rows) and makes the data available throughout the workbook (as opposed to defining
connections on each worksheet). In addition it allows you to integrate BI objects you create in Excel
with SharePoint. It requires Excel 2010.
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 25 of 26
We won’t be creating portals or dashboards in this class. However if you have been exposed to Tableau,
it is good to know that Tableau can access data and objects from SSAS as well as PowerPivot and can be
used to create dashboards.
References:
SharePoint: http://www.cmswire.com/cms/enterprise-20/what-is-sharepoint-2010-vision-and-reality007513.php
PerformancePoint 2010: http://technet.microsoft.com/en-us/library/ee661741.aspx
PowerPivot: http://msdn.microsoft.com/en-us/library/ee210692.aspx
PerformancePoint and PowerPivot: http://denglishbi.wordpress.com/2011/01/03/using-powerpivotwith-performancepoint-services-pps-2010/ and http://uttkarshkalia.wordpress.com/2010/05/04/sqlserver-powerpivot-for-excel-2010-sharepoint-2010-deliver-and-succeed-with-bi/
PerformancePoint Dashboard Demo:
http://richardlees.com.au/sites/Demonstrations/Shared%20Documents/Foodmart/Foodmart%20Dashb
oard.aspx
Tableau and SQL Server Analysis Services: http://www.sqlservian.com/2010/09/ssas-and-tableaudesktop-professional-better-together/
Instructor Notes: Create Class Performance Cube
4/2/2015 1:30 PM
Page 26 of 26