







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Use the metadata pane to add a measure to a query Use the metadata pane to add a function to a query
o Access cell properties o Access cells in a cube using partial tuples
Using the MDX Query Editor
Connect to an Analysis Services instance using SQL Server Management Studio
1. On the Microsoft Windows task bar, click the Start button. 2. From the Start Menu, select All Programs and then select Microsoft SQL Server 2008 to expose the SQL Server Management Studio shortcut. 3. Click the SQL Server Management Studio shortcut to launch the application. 4. Use the Server Type drop-down list to select the Analysis Services server type. 5. In the Server Name field, type local host. You will see the screen shown in Fig 1
Figure: 1
6. Click Connect to establish a connection to Analysis Services. You are now connected .you will see the screen shown in Fig 2
Figure: 2
Figure: 4
8. Click Execute on the Query Editor Toolbar to execute the query. In addition to the messages pane, Notice that the results pane is now presented. 9. Review the data returned within the results pane.
Figure: 5
10. Select the messages tab and review the information presented. Pay particular attention to the number of columns and rows returned. Compare these to the data in the results pane.
Figure: 6 Congratulations! You have just successfully assembled and executed a simple MDX query using the MDX Query Editor.
Building a More Complex Query
1. Open the MDX Query Editor to the MDX Step-by-Step database. 2. Configure the metadata pane to display the contents of the Step-by-Step cube. 3. In the code pane, enter the following query: SELECT FROM [Step-by-Step] 4. Parse the query to verify its syntax. Correct any problems identified. 5. Add a third line to the query containing the keyword WHERE followed by a single space: SELECT FROM [Step-by-Step] WHERE 6. In the metadata pane, locate and expand the Date dimension. 7. Locate the CY 2004 member in the Date dimension’s Calendar Year attribute-hierarchy. You can hover over the CY 2004 member to display its tool tip. Notice that each member item presents the member’s name while the tool tip lists both the member’s key and name. As shown in Fig. 6
Figure: 6
8. Drag the CY 2004 member to the code pane to the right of the keyword WHERE : SELECT FROM [Step-by-Step] WHERE [Date].[Calendar Year].&[2004] Notice that dragging a member from the metadata pane to the code pane causes a member key reference to be placed in the code. 9. Execute the query and review the results.
5. Execute the query and review the results.
Figure: 9
Use the metadata pane to add a function to a query
1. Ensure that you begin with the MDX query completed in the previous exercise: SELECT [Measures].[Reseller Sales Amount] ON COLUMNS FROM [Step-by-Step] WHERE [Date].[Calendar Year].&[2004] 2. Insert a comma at the end of the first line, just after the phrase ON COLUMNS. Press Enter to create a new line following this: SELECT [Measures].[Reseller Sales Amount] ON COLUMNS , FROM [Step-by-Step] WHERE [Date].[Calendar Year].&[2004] 3. Using the metadata pane, drag the Product dimension’s Category attribute-hierarchy to the blank line just above the line starting with the FROM keyword: SELECT [Measures].[Reseller Sales Amount] ON COLUMNS, [Product].[Category] FROM [Step-by-Step] WHERE [Date].[Calendar Year].&[2004] 4. In the metadata pane, switch to the Functions tab. 5. Expand the Set folder and locate the first Members function item. As shown in Fig. 10
Figure: 10
6. Hover over the Members function item to display its tool tip. Notice that functions display their syntax And a brief definition in their tool tips. 7. Drag the Members function item to the right of the [Product].[Category] phrase to assemble the following statement: SELECT [Measures].[Reseller Sales Amount] ON COLUMNS, [Product].[Category] «Hierarchy».MEMBERS FROM [Step-by-Step] WHERE [Date].[Calendar Year].&[2004] 8. Remove the «Hierarchy» placeholder, making certain to leave no spaces between [Product].[Category] and .Members : SELECT [Measures].[Reseller Sales Amount] ON COLUMNS, [Product].[Category] .MEMBERS FROM [Step-by-Step] WHERE [Date].[Calendar Year].&[2004] 9. Complete the second line by appending ON ROWS to it: SELECT [Measures].[Reseller Sales Amount] ON COLUMNS, [Product].[Category].MEMBERS ON ROWS FROM [Step-by-Step] WHERE [Date].[Calendar Year].&[2004] 10. Execute the query and note the values returned. Result is shown in Fig. 11
Accessing Data with Tuples
1. Open MDX Query Editor 2. Verify that the MDX Step-by-Step database is selected within the Query Editor Toolbar. 3. In the metadata pane, use the Available Cubes drop-down list to select the Chapter 3 cube.
Figure: 1
Use a tuple to access a point in a cube space
1. Open the MDX Query Editor to the MDX Step-by-Step database. 2. In the code pane, enter the following query: SELECT FROM [Chapter 3 Cube] WHERE ( [Date].[Calendar Year].[All Periods], [Date].[Fiscal Year].[All Periods], [Product].[Category].[Bikes], [Product].[Subcategory].[Mountain Bikes], [Measures].[Measures].[Reseller Sales Amount] ) 3. Execute the query.
Figure: 2
4. Move the [Product].[Subcategory].[Mountain Bikes] member reference to the top of the tuple: SELECT FROM [Chapter 3 Cube] WHERE ( [Product].[Subcategory].[Mountain Bikes], [Date].[Calendar Year].[All Periods], [Date].[Fiscal Year].[All Periods], [Product].[Category].[Bikes], [Measures].[Measures].[Reseller Sales Amount] ) 5. Execute the query and verify the same value as before is returned.
Try moving around other member references within the tuple. Notice that so long as the tuple is properly formed, the same point within the cube space is identified.
Access cell properties
1. On the Toolbar click the icon New Query 2. In the metadata pane, use the Available Cubes drop-down list to select the Chapter 3 cube. 3. In the code pane, re-enter the last query from the previous exercise: SELECT FROM [Chapter 3 Cube] WHERE ( [Product].[Subcategory].[Mountain Bikes], [Date].[Calendar Year].[All Periods], [Date].[Fiscal Year].[All Periods], [Product].[Category].[Bikes], [Measures].[Measures].[Reseller Sales Amount] ) 4. Execute the query to retrieve the results. You will see the same results as you viewed in the last query in Fig. 2 5. Double-click the cell returned in the Results pane to open the Cell Properties dialog box. As shown in Fig. 3
Figure: 3
6. Click the OK button in the Cell Properties dialog box to close it.
Access cells in a cube using partial tuples
Figure: 1
Reference : Microsoft SQL Server 2008 MDX – Step by Step