advanced olap data sources with mdx

61
SQL SERVER 2008 REPORTING SERVICES ADVANCED OLAP DATA SOURCES WITH MDX SetFocus Business Intelligence Master’s Program

Upload: shangz-brown

Post on 07-Mar-2015

362 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Advanced OLAP Data Sources With MDX

SQL SERVER 2008 REPORTING SERVICES

ADVANCED OLAP DATA SOURCES WITH MDX

SetFocus Business Intelligence Master’s Program

Page 2: Advanced OLAP Data Sources With MDX

Table of Contents

Chapter Slide #

Chapter Objectives 3

Summary of Examples 4

Visual Studio Project File 5

Creating the Shared Data Source 6

Example 1: Basic PIVOT table

Example 2: Trend line chart with a 12-month moving average 7

Example 3: a nested MDX TOPCOUNT and an MDX RANK, over a user-defined date range 16

Example 4: showing KPIs 24

Example 5: Cascading Parameters with OLAP data 32

Example 6: (Quarter Parameter, show data for current/prior quarter, annotate both dates) 39

Example 7: Data Mining

2

Page 3: Advanced OLAP Data Sources With MDX

Chapter Objectives

Show how to create reports against OLAP databases without writing any MDX code

Show how to override the MDX that SSRS generates, with custom MDX

Modify the query parameters that SSRS generates Manually create our own query parameters Create reports against Analysis Services KPIs Show how to implement reports with cascading parameters Show reports against Data Mining Models

3

Page 4: Advanced OLAP Data Sources With MDX

Examples in this chapter

1. Creating a Matrix/Pivot table report with drilldown capabilities

2. Creating a trend line chart with a 12-month moving average (using a pre-written MDX calculated member to determine the 12-month moving average)

3. Create a report that generates a nested MDX TOPCOUNT and an MDX RANK, over a user-defined date range

4. Create a report that retrieves KPIs

5. Implementing Cascading Parameters with OLAP data

6. Create a report with a Quarter Parameter, show data for current and prior quarter, and annotate both dates

7. Create a report against a data mining model

4

Page 5: Advanced OLAP Data Sources With MDX

Visual Studio Project File

The project that we’ll create consists of: A Shared Data Source for the Waremart OLAP Database

on the SFMPBISQL\SQL2005 server (see next slide for details on creating the shared data source)

Five report RDL files

5

Page 6: Advanced OLAP Data Sources With MDX

Creating the Shared Data Source

To create the shared data source:1. Right-click on the Shared Data

Sources folder and select Add New Data Source

2. Give the Data Source a name (dsWareMartOLAP), and select Microsoft SQL Server Analysis Services as the Data Source Type

3. Click the EDIT button to edit the connection properties. In the Connection Properties window, enter the server name (SFMPBISQL\SQL2005), and select Waremart 2005 as the OLAP database

6

Page 7: Advanced OLAP Data Sources With MDX

Creating a trend line chart with a 12-month moving average using MDX

rpt01_BasicOLAP.rdl

Demo: Example 17

Page 8: Advanced OLAP Data Sources With MDX

Demo 1, End result

Report prompts for a geography selection (either All, or a country, or a state, or a city)

Report shows Internet Sales on the row axis, by Product Category, Product SubCategory, and individual product (using SSRS drilldown feature)

Report also breaks down sales by Fiscal year and Fiscal quarter on the column axis, using the same drilldown feature

8

Page 9: Advanced OLAP Data Sources With MDX

Demo 1: Steps to reproduce

1. Create a new report (rpt01_BasicOLAP.rdl)

2. Create a new DataSet (using the shared Data Source dsADW2008OLAP), selecting Fiscal Year & Fiscal Quarter of Year, Product Category/Product SubCategory/Product, and one measure (Internet Sales) for the output

3. Define a Parameter based on the Customer dimension/Customer Geography Hierarchy

1. Visual Studio will auto-generate a dataset with MDX code for this parameter.

2. We will want to modify the MDX code to only show Geography down to the state level

3. That will require a manual change to the RDL file, so that Visual Studio will never overwrite our MDX modifications

4. Create a Matrix report that will contain Row Groups for Category – SubCategory – Product, and column Groups for Fiscal Year - Quarter

5. Add totals and drilldown capabilities for the necessary groups

6. Annotate the page headings for the Parameters selected

9

Page 10: Advanced OLAP Data Sources With MDX

Demo 1, DataSets and Parameters

Report will contain the following: DataSets

dsSales CustomerCustomerGeography (Generated by SSRS)

Parameters @CustomerCustomerGeography (Generated by SSRS)

Matrix Column Groups for FY Year and Quarter Row Groups for Product Category/SubCategory/Product

10

Page 11: Advanced OLAP Data Sources With MDX

Demo 2, Step 1 of 7 Create a new dataset called dsSales Drag in the following from the

metadata on the left: Date…Fiscal…Fiscal Year and Fiscal

Quarter of Year Product….Category, SubCategory,

and Product Measures….Internet Sales Amount

Create a dimension filter parameters at the top (SSRS will automatically generate DataSets for the dropdown): Customer…Customer Geography Make sure to check the Parameters

checkbox Visual Studio will generate a hidden

dataset with MDX code, to populate a dropdown list

We only want the user to make a Geography selection down to the City level.

Ideally, we’d have a subset hierarchy in the dimension cube – but since we don’t, we’ll need to modify the generated MDX (see next steps)

11

Page 12: Advanced OLAP Data Sources With MDX

Demo 2, Step 2 of 7

Reporting Services 2008 has default behavior we need to modify

In the prior step, we created a parameter for the Geography Hierarchy. As a result, SSRS automatically generated a second dataset with

MDX code to populate a parameter dropdown (and that’s a good thing)

SSRS (Visual Studio) also allows us to modify the MDX code for that second dataset, if we only want a subset of the hierarchy (and that’s also a good thing)

However, by default, if we ever go back and modify the first dataset, or modify the new report parameter, Visual Studio will regenerate the MDX dataset code. This will overwrite our custom changes – and that’s NOT a good thing!!!

Fortunately, there’s a workaround. You must do this BEFORE modifying any of the generated MDX code: Close the report designer, but keep the overall SSRS project open In Solution Explorer, right click on the report, and take the View

Code Option For each instance of a </Query>..</DataSet> combination, enter

the following: <rd:SuppressAutoUpdate>true</

rd:SuppressAutoUpdate>

Save the code, close the code window and reload the report in the Visual Studio designer

12

Developer Alert! SSRS has a UFO (Undesirable Feature Object) that we must address

Page 13: Advanced OLAP Data Sources With MDX

Demo 2, Step 3 of 7

After modifying the report RDL to suppress any auto-generation of MDX datasets, we can modify the MDX code in the 2nd dataset.

By default, MDX-generated datasets don’t appear in the Report Data Window pane. We need to right-click on the data source, and select Show Hidden DataSets.

Visual Studio will then display the 2nd hidden dataset (CustomerCustomerGeography). We can right-click on the dataset and modify the query

13

Page 14: Advanced OLAP Data Sources With MDX

Demo 2, Step 4 of 7

In the generated MDX code, change the ON rows statement to the following:

DESCENDANTS( [Customer].[Customer Geography],

[Customer].[Customer Geography].[City],

SELF_AND_BEFORE) ON ROWS

Make sure to execute the code (using the icon) to test the result set

14

Page 15: Advanced OLAP Data Sources With MDX

Demo 2, Step 5 of 7

Drag a Matrix control into the report body Drag the Category column from the Dataset into the

Matrix (into the Rows area) Drag the FiscalYear column from the Dataset into the

Matrix (into the columns area) Drag the InternetSalesAmount from the Dataset into the

Matrix (into the Data area) To add the additional row groups:

Click on the dropdown for Category (in the Row Group area) and add a Group (as a child group) and select the SubCategory as the column for the group.

Right-click on the new Subcategory group (which is probably called “Group1”) and go to the properties. Change the name of the group to grpSubCategory.

Click on the dropdown for the new Subcategory group (in the Row Group area) and add a group (as a child group) and select the Product as the column for the group.

Right-click on the new Product group (which might also be called “Group1”) and go to the properties. Change the name of the group to grpProduct.

To add total sections for the row groups: For each of the row groups, click the specific dropdown and

select Add Total - Before

15

Page 16: Advanced OLAP Data Sources With MDX

Demo 2, Step 6 of 7

To add the additional column groups: Click on the dropdown for Fiscal Year (in the Column Group area)

and add a Group (as a child group) and select the Fiscal Quarter of Year as the column for the group.

Right-click on the new Fiscal Quarter group (which is probably called “Group1”) and go to the properties. Change the name of the group to grpQuarter.

To add total sections for the column groups: For each of the column groups, click the specific dropdown and

select Add Total – Before

For each of the open cells in the matrix where you’d want a total, click the small grid in the upper right corner and select the Internet Sales amount. (Alternatively, you can drag the sales amount from the DataSet into the cell)

16

Page 17: Advanced OLAP Data Sources With MDX

Demo 2, Step 7 of 7

To implement drilldown in the row and column area: First, make sure all the textboxes in the Matrix (for Category –

Subcategory – Product, and Fiscal Year – Fiscal Quarter) are named appropriately (e.g. txtSubCategory). The drilldown feature will reference these textboxes by name.

For the grpProduct group, right-click, go to properties, go to the Visibility section, and set Hidden to True and Toggleitem to the textbox for SubCategory

For the grpSubCategory group, right-click, go to properties, go to the Visibility section, and set Hidden to True and ToggleItem to the textbox for Category.

17

Page 18: Advanced OLAP Data Sources With MDX

Creating a trend line chart with a 12-month moving average using MDX

rpt02_MovingAverageOLAP.rdl

Demo: Example 218

Page 19: Advanced OLAP Data Sources With MDX

Demo 2: End Result

Report shows sales dollar revenue as a column bar and the 12 month moving average as a horizontal line

The trend line helps to visually assess if monthly revenue is above or below the 12 month average (at that month)

User can select one or more years, and a product category or subcatregory

19

Page 20: Advanced OLAP Data Sources With MDX

Demo 2: Steps to reproduce

1. Create a new report (rpt01_TwelveMonthMovingAverage.rdl)2. Create a new DataSet, selecting Months and two measures

(Revenue and 12 month moving average) for the output 3. Define two parameters for Year and Geography 4. Create a chart that will plot the Monthly Revenue as a column

bar and the 12 month moving Avg for Revenue as a line, with Months as the X-Axis

5. Customize the chart (colors, legend placement, etc.)6. Annotate the page headings for the Parameters selected

20

Page 21: Advanced OLAP Data Sources With MDX

Demo 2, DataSets and Parameters

Report uses the following: DataSets

dsSales TimeYear (Generated by SSRS) CustomerRegionToCity (Generated by SSRS)

Parameters TimeYear (Generated by SSRS) CustomerRegionToCity (Generated by SSRS)

21

Page 22: Advanced OLAP Data Sources With MDX

Demo 2, Step 1 of 5

Create a new dataset Drag in the following from the left:

Time…Month Measures….Dollar Sales Measures…12 Month Avg

Create two dimension filter parameters at the top (SSRS will automatically generate DataSets for the dropdowns): Time….Year (default to 2005) Customer…RegionToCity (default to ALL)

For reference, the MDX code for 12 month average uses the MDX functions AVG and LASTPERIODSavg ( LastPeriods(12,[Time].[Month].PrevMember), [Measures].[dollar Sales])

22

Page 23: Advanced OLAP Data Sources With MDX

Demo 2, Step 2 of 5

Go to Layout Drop a chart from the toolbox into

the report body Stretch the chart as far out as your

wish Drag Month from DataSets to the X-

axis (Drag Category Fields here) Drag Dollar Sales and 12 Month Avg

from DataSets to Drag Data Fields here

23

Page 24: Advanced OLAP Data Sources With MDX

Demo 2, Step 3 of 5

Right-click on Chart Properties Go to Legend Set Layout to Row Click on bottom center for position

Right-click on ID12MonthAvg Change Series Label to “12 Mnth Avg” Go to Appearance….check Plot Data As Line

Right-click on Chart Properties (again) Go to Plot Area Style Go to FILL Create a Gradient Fill Then go to Y-Axis Enter “Revenue “for Title and “C0” for

Format Code

24

Page 25: Advanced OLAP Data Sources With MDX

Demo 2, Step 4 of 5

For both Parameters, turn multi-value OFF Under the layout tab, select the Report Menu Select Parameters Note that SSRS already generated the TimeYear

and CustomerRegionToCity report parameters, when we created the query parameters (Slide 11)

Turn Multi-value OFF for both parameters (by default, SSRS makes OLAP parameters MULTI-VALUE)

Note that each of the 2 generated parameters has an associated DataSet that SSRS also generated.

If you want to see the DataSets that SSRS generated, go back to the data tab, click the DataSet pulldown, and review the MDX code for the 2 new DataSets

25

Page 26: Advanced OLAP Data Sources With MDX

Demo 2, Step 5 of 5

Create a Page Heading to annotate the parameter values Select the Report Menu, select Page Header Create a textbox in the header

Enter the following expression:

= "Revenue and 12 Month Moving Average for “ & ltrim(Parameters!CustomerRegionToCity.Label)

& " for " & ltrim(Parameters!TimeYear.Label)

Finally, to get the data recap below the graph: Drag a table object from the toolbox, and place it below the

chart Drag in the Month, Dollar Sales, and 12 Month Average into

the columns (and format the Dollar Sales and 12 Month Average as currency)

You’re finished! Go ahead and Preview

26

Page 27: Advanced OLAP Data Sources With MDX

Demo 2, Final notes

Note that the Region to City dropdown is not a true hierarchical dropdown

You can’t expand/collapse the regions – the dropdown is a flat indented list

Not very practical for viewing the hierarchy

Two alternatives to get a true hierarchical, tree-like dropdown: If deploying to a native SSRS server, build an

ASP.NET webpage to create a better dropdown If deploying to MOSS (SharePoint Server),

MOSS has web parts that allow us to create better dropdowns

27

Page 28: Advanced OLAP Data Sources With MDX

Create a report that generates a nested MDX TOPCOUNT and an MDX Ranking over a user-defined date range

rpt03_TopProductsAndCitiesOLAP.rdl

Demo: Example 328

Page 29: Advanced OLAP Data Sources With MDX

Demo 3: End Result

Report allows the user to see the TOP N Regions by Revenue, and within each region, the TOP Y categories

Report allows the user to select a range of months

29

Page 30: Advanced OLAP Data Sources With MDX

Demo 3: Steps to reproduce

1. Create a new report (rpt03_NestedTopCountWithDateRange.rdl)

2. Create a new DataSet and manually enter MDX code to deal with a NESTED TOPCOUNT

3. Manually create parameters for the Customer and Product TOPCOUNT limits

4. Create a Parameter for the time Period5. Define the Layout

30

Page 31: Advanced OLAP Data Sources With MDX

Demo 3, DataSets and Parameters

Report uses the following: DataSets

dsSales MonthStart (generated automatically by SSRS) MonthEnd (generated automatically by SSRS)

Parameters MonthStart (generated automatically by SSRS) MonthEnd (generated automatically by SSRS) TopRegionCount (unbound parameter, manually created) TopProductCount (unbound parameter, manually created)

31

Page 32: Advanced OLAP Data Sources With MDX

Demo 3, Step 1 of 4

1. Click the DataSet pulldown

2. Create a new dataset (dsSales) Enter the MDX Code: (provide code)

WITH SET [RegionSet] AS Topcount ([Customer].[Region].children,@TopRegionCount , [Measures].[Dollar Sales])

SET [MainSet] AS GENERATE( [RegionSet] , ( [Customer].[Region].CurrentMember, TOPCOUNT( [Product].[Category].Children, @TopProductCount, [Dollar Sales])))

member [RankProd] as RANK( ([Customer].[Region].currentmember, [Product].[Category].currentmember), exists([MainSet], [Customer].[Customer].CurrentMember))

member [RankCust] as RANK( ([Customer].[Region].currentmember), [RegionSet])

select {[Measures].[Dollar Sales], [RankCust], [RankProd]} ON columns, [MainSet] on rowsfrom sales where ( strtomember(@MonthStart) : strtomember(@MonthEnd) )

32

Page 33: Advanced OLAP Data Sources With MDX

Demo 3, Step 2 of 4

1. Click the Query Parameters button and enter the following query parameters:1. TopRegionCount

2. TopProductCount

3. MonthStart (using the Time/Month Dimension/Hierarchy)

4. MonthEnd (using the Time/Month Hierarchy)

33

Page 34: Advanced OLAP Data Sources With MDX

Demo 3, Step 3 of 4

1. Design the report layout1. Build a basic group for the Region

2. Add the Ranking numbers for both the Region and Product

3. Build a long header expression based on the parameters

= "Top " & Parameters!TopRegionCount.Value & " Regions and Top " & Parameters!TopProductCount.Value & " Products from “ & Parameters!MonthStart.Label & " to " & Parameters!MonthEnd.Label

34

Page 35: Advanced OLAP Data Sources With MDX

Demo 3, Step 4 of 4

1. Report Parameter Screen1. You can mimic a pulldown for the

topcounts by placing pairs of sequence values (1, 2, 3, etc.) in the Available values

35

Page 36: Advanced OLAP Data Sources With MDX

Create a report that retrieves KPIs

rpt04_UsingKPIOLAP.rdl

Demo: Example 436

Page 37: Advanced OLAP Data Sources With MDX

Demo 4: End Result

Even if an organization doesn’t use SharePoint/PerformancePoint, you can still render KPIs graphically in an SSRS report

Important step beforehand: Create a folder under C:\INETPUB\

WWWROOT, called KPIImages (two I’s)

Save the following six images to that folder: RedImage.JPG, GreenImage.JPG,

YellowImage.JPG DownArrow.JPG, UpArrow.JPG,

RightArrow.JPG

37

Page 38: Advanced OLAP Data Sources With MDX

Demo 4: Steps to reproduce

1. Create a new report (rpt04_UsingKPIs.rdl)2. Drag in Product Category, Sales, and KPI information3. Create Parameter filters for Time/Quarter and Customer

Region4. Lay out the report5. Create expressions to dynamically load images for KPIs 6. Set report column headings for interactive sorting

38

Page 39: Advanced OLAP Data Sources With MDX

Demo 4, DataSets and Parameters

Report uses the following: DataSets

dsSales TimeQuarter (generated automatically by SSRS) CustomerRegion (generated automatically by SSRS)

Parameters TimeQuarter (generated automatically by SSRS) CustomerRegion (generated automatically by SSRS)

39

Page 40: Advanced OLAP Data Sources With MDX

Demo 4, Step 1 of 4

1. Drag in the following from the Cube Browser1. Prod Category

2. Dollar Sales and Returns

3. KPI Returns Pct1. Value, Status, Trend

2. Note that the result set doesn’t contain images for the KPI Status and Trend – just the numeric values

3. We can build images dynamically based on the 3 values

4. Create 2 Parameter Filters for Time/Quarter and Customer/Region

40

Page 41: Advanced OLAP Data Sources With MDX

Demo 4, Step 2 of 4

1. Create the layout as shown on the left

2. Create empty Image controls for the KPI Status and Trend1. Drop an instance of the image control

into the two columns for Status and Trend

2. When the image wizard comes up each time, simply click FINISH (we don’t want to use the image wizard)

3. We will use dynamic image capabilities next

41

Page 42: Advanced OLAP Data Sources With MDX

Demo 4, Step 3 of 4

1. Create a report Report Pararameter called KPIPicLocation (as a hidden parameter)1. Click the Report menu dropdown, select

Parameters, and add a new Parameter called KPIPicLocation, and make it hidden

2. Provide a value for the location of the images: http://localhost/KPIImages/

2. For the KPI Status Image, enter the following formula (click on the image, hit F4 to access the property sheet, and go to the VALUE property) (provide code)=switch( Fields!KPIReturnsPct_Status_.Value=1, Parameters!KPIPicLocation.Value & "greenimage.jpg",

Fields!KPIReturnsPct_Status_.Value=0, Parameters!KPIPicLocation.Value & "yellowimage.jpg",

Fields!KPIReturnsPct_Status_.Value=-1,Parameters!KPIPicLocation.Value & "redimage.jpg")

42

Page 43: Advanced OLAP Data Sources With MDX

Demo 4, Step 4 of 4

1. Repeat the previous step for the KPI Trend Indicator (provide code)

=switch( Fields!KPIReturnsPct_Trend.Value=1, Parameters!KPIPicLocation.Value & "uparrow.jpg",

Fields!KPIReturnsPct_Trend.Value=0, Parameters!KPIPicLocation.Value & "rightarrow.jpg",

Fields!KPIReturnsPct_Trend.Value=-1, Parameters!KPIPicLocation.Value & "downarrow.jpg")

2. Miscellaneous steps:Turn off multi-value for report parameters

Create a Page Header to annotate the Parameters chosen

Turn on column heading interactive sorting

43

Page 44: Advanced OLAP Data Sources With MDX

Implementing Cascading Parameters with OLAP data

rpt05_CascadingParmOLAP.rdl

Demo: Example 544

Page 45: Advanced OLAP Data Sources With MDX

Demo 5: End Result

Report will demonstrate cascading parameters

User will select a city, and then SSRS will only show the product SKUs in distribution for the city

This could mean the difference between the SKU dropdown being thousands of items, or maybe just a dozen items

45

Page 46: Advanced OLAP Data Sources With MDX

Demo 5: Steps to reproduce

1. Create a new report (rpt05_OLAPCascadingParameters.rdl)2. Create a new DataSet that shows Dollar Sales by Day, with

parameters for Customer/City, Product/SKU3. Define the 2nd Parameter (Product) to only show products

that were sold for the account selected (cascading parameter)

46

Page 47: Advanced OLAP Data Sources With MDX

Demo 5, DataSets and Parameters

Report uses the following: DataSets

dsSales CustomerCity (generated automatically by SSRS) ProductRTProdSKU (generated automatically by SSRS)

Parameters CustomerCity (generated automatically by SSRS) ProductRTProdSKU (generated automatically by SSRS)

47

Page 48: Advanced OLAP Data Sources With MDX

Demo 5, Step 1 of 3

1. Drag in the following from the Cube Browser1. Time….Day

2. Dollar Sales

2. Create 2 Parameter Filters for Customer/City and Product/SKU

48

Page 49: Advanced OLAP Data Sources With MDX

Demo 5, Step 2 of 3

1. Now we need to modify the Product DataSet, so that the Report Parameters will only list those products that were sold for the current selected account

2. Go to the DataSet ProductRTProdSKU (sometimes you don’t see the dataset right away…click on LAYOUT and then back to DATA)

3. Change the MDX code – specifically, change the ON ROWS statement to the following: (provide code) filter( [Product].[Rt Prod Sku].children, [dollar sales] > 0) ON ROWS

FROM ( SELECT ( STRTOSET(@CustomerCity, CONSTRAINED) ) ON COLUMNS FROM [Sales])

49

Page 50: Advanced OLAP Data Sources With MDX

Demo 5, Step 3 of 3

1. Build the layout (just a Detail Level for Day and Dollar Sales)

2. Annotate the Parameters at the top

50

Page 51: Advanced OLAP Data Sources With MDX

Create a report with a Quarter Parameter, show data for current and prior quarter, and annotate both dates

rpt06_QuarterTrendOLAP.rdl

Demo: Example 651

Page 52: Advanced OLAP Data Sources With MDX

Demo 6: End Result

Uses OLAP database dsWareMart

Use SSRS OLAP Designer for the measures

Use custom MDX to set the default for the Quarter Parameter to most recent quarter

This report may initially seem easy, but as it turns out, requires a great deal of MDX

We need to create MDX DataSets to determine the most recent quarter, and to determine the previous quarter

52

Page 53: Advanced OLAP Data Sources With MDX

Demo 6: Steps to reproduce

1. Create a new report (rpt06_QuarterParameter.rdl)2. Create a new DataSet and include a Quarter Dimension

Parameter3. Verify the new Quarter Parameter4. Build a new DataSet to determine the most recent quarter5. Map the DataSet to the quarter Dimension Parameter6. Create a new DataSet with MDX code to determine the

previous quarter7. Create an invisible parameter to hold the label for the previous

quarter8. Define the Layout

53

Page 54: Advanced OLAP Data Sources With MDX

Demo 6, DataSets and Parameters

Report uses the following: DataSets

dsSales TimeQuarter (Generated by SSRS) dsPreviousQuarter dsQuarterDefault

Parameters TimeQuarter (Generated by SSRS) PreviousQuarter

54

Page 55: Advanced OLAP Data Sources With MDX

Demo 6, Step 1 of 7

1. Click the DataSet pulldown

2. Create a new dataset (dsSales)

3. Select the Customer Region attribute and drag it into the grid results

4. Select the 2 measures [Dollar Sales] and [DollarSalesPreviousTime] and drag them into the grid results

5. Create the Quarter Parameter1. Select the Time/Quarter attribute hierarchy

2. Provide an initial default value (again, we’ll change programmatically)

3. Make it a parameter

6. SSRS adds a new DataSet for the Time/Quarter Parameter (TimeQuarter)

55

Page 56: Advanced OLAP Data Sources With MDX

Demo 6, Step 2 of 7

1. Go to the Layout Tab

2. Click the Report Parameters menu pulldown

3. Note that SSRS automatically creates a report parameter (on Quarter) from the previous screen

4. Change the Prompt

56

Page 57: Advanced OLAP Data Sources With MDX

Demo 6, Step 3 of 7

1. Must tweak the MDX that the SSRS designer made for the Time/Year Parameter (we don’t want see the ALL Member)

2. Go to the TimeQuarter DataSet

3. Change the ON ROWS statement to the following (basically change ALLMEMBERS to Children):[Time].[Quarter].children ON ROWS

57

Page 58: Advanced OLAP Data Sources With MDX

Demo 6, Step 4 of 7

1. Create a new DataSet

2. Call it dsQuarterDefault

3. Will contain one row, for the most recent quarter of available data

4. Go into MDX mode

5. Add the following MDX code: (provide code)

WITH MEMBER [Measures].[ParameterValue] AS [Time].[Quarter].CURRENTMEMBER.UNIQUENAME

SELECT [Measures].[ParameterValue] ON COLUMNS ,

TAIL( FILTER([Time].[Quarter].children, [Dollar Sales]),1)

ON ROWS

FROM [Sales]

58

Page 59: Advanced OLAP Data Sources With MDX

Demo 6, Step 5 of 7

1. Go back to Layout

2. Go back to Report Parameters

3. For the TimeQuarter Parameter:

1. Change the Default Values to “From Query”

2. Set the DataSet to dsQuarterDefault

3. Set the Value Field to ParameterValue

This will force the Timequarter dropdown to always default to the most recent quarter

59

Page 60: Advanced OLAP Data Sources With MDX

Demo 6, Step 6 of 7

1. Create a new DataSet

2. Call it dsPreviousQuarter

3. Will contain one row, for the previous quarter from the current quarter member

4. Go into MDX mode

5. Click the Query Parameters button ( ) and enter the query parameter for Time Quarter (see lower left of this slide)

6. Add the following MDX code: (provide code)WITH MEMBER [Measures].[ParameterCaption] AS[Time].[Quarter].CURRENTMEMBER.MEMBER_CAPTION

SELECT [Measures].[ParameterCaption] ON COLUMNS , STRTOMEMBER(@TimeQuarter).PrevMember ON ROWS FROM SALES

60

Page 61: Advanced OLAP Data Sources With MDX

Demo 6, Step 7 of 7

1. Go back to Report Layout

2. Create a new Report Parameter called PreviousQuarter (we’ll use this parameter to “capture” the value from dsPreviousQuarter)1. Check the Hidden checkbox

2. Change the Default Values to “From Query”

3. Set the DataSet to dsPreviousQuarter

4. Set the Value Field to ParameterCaption

61