Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Feb 6, 2006

MDX Set Functions: DrillDownLevel() - Page 5

By William Pearson

The report authors outline the next drilldown scenario as follows: using the Adventure Works cube, once again, as a data source, they wish to create a query that returns information surrounding the composition of select sales from the perspective of customer locations. Specifically, they wish to present comparative Internet Sales for all Calendar Years contained in the cube, for United States customers, in such a way that the states within which sales took place are summarized. The drilldown requirement in this case consists in the need to present the total sales for the United States, drilled down to the sales totals for the states, which make up the U.S. total. The report authors are convinced that, once they achieve this objective, the capability to perform ad hoc drilldowns on a given state (or a group of states) at runtime will become a matter of parameterizing the key component of the row axis specification within the MDX query involved, a mechanism that can be leveraged, as one example, in a summary / target report pairing (as well as through other avenues) within Reporting Services, such as we have discussed earlier.

To outline the requirement further, our "confirmation of understanding draft," again in MS Excel, is depicted in Illustration 12.


Illustration 12: "Confirmation Draft" of the Proposed Dataset

We obtain consensus on the dataset, and set about constructing the query.

4.  Replace the syntax from our initial query in the Query pane by typing (or cutting and pasting) the following in its place:


--- MDX040-002-1 DrillDownLevel() 
 With Level Expression Option - Before
SELECT
 CROSSJOIN({[Date].
 [Calendar Year].Members},{[Measures].
   [Internet Sales Amount]}) ON COLUMNS,
 NON EMPTY(DRILLDOWNLEVEL( {
   [Customer].[Customer Geography].
   [Country].[United States]}
 )) ON ROWS
FROM 
  [Adventure Works]

The Query pane appears, with our input, as shown in Illustration 13.


Illustration 13: Second Query in the Query Pane ...

5.  Select File --> Save MDX040-001 As..., name the file MDX040-002-1, and place it in a meaningful location, to protect the former query.

6.  Execute the query by clicking the Execute button in the toolbar, as before.

The Results pane is populated by Analysis Services, and the dataset shown in Illustration 14 appears.


Illustration 14: Results Dataset – Another Basic Use of DrillDownLevel() Function

In the returned dataset, we see that Country United States (the top row of the dataset) is presented in "rolled up" state. The states, within which we have conducted Internet Sales transactions, within the Calendar Years contained within the Adventure Works cube, appear underneath the United States summary line. The states represent the drilled down children of Country United States, whose values add up to the Country United States total. The query has returned the "next level down" from the United States level, or all States with activity. This, as we have discussed, is the default, most straightforward use of DrillDownLevel().

7.  Select File --> Save MDX040-002-1.mdx to ensure that the file is saved. (Leave MDX040-002-1.mdx open for the next steps).

The developers / authors again express satisfaction with the results, agreeing that the current point is a good place from which to demonstrate the use of the optional Level Expression option that we have explained to them in introductory discussions. We agree that a useful next step will be a further extension of the query. As an example of the process involved, the developers / authors wish to see how they might easily make it possible to leverage the Level Expression to direct the function to return members from a specific level underneath the Country United States set ( {[Customer].[Customer Geography].[Country].[United States]} ). As an illustrative example, they wish to direct drill down explicitly to the City level from the current point, and to therefore return the child Cities (with values) for each of the States currently presented, and to display their sales contributions, in turn, to the United States Internet Sales total.

We reiterate that the optional Level Expression exists specifically for this purpose, and take the following steps to demonstrate its operation.

8.  Modify the top line in the query (the commented line) to the following:

--- MDX040-002-2 DrillDownLevel() With Level Expression Option - "After"

9.  Select File --> Save MDX040-002-1 As..., name the file MDX040-002-2, placing it with the previous to query files, to protect the former query.

10.  Place a comma (",") after the existing Set Expression within the Rows axis specification (That is, {[Customer].[Customer Geography].[Country].[United States]} ).

11.  Create a space below [Customer].[Customer Geography].[Country].[United States] using the Enter key just after the newly added comma, pushing down the row containing the ON ROWS keywords in the process.

12.  Insert the following into the space below (between the existing Set Expression and the ON ROWS keywords)

 [Customer].[Customer Geography].[State-Province]

The Query pane appears, with the areas affected by our modifications circled, as depicted in Illustration 15.


Illustration 15: Our Second Query, with Modifications

13.  Execute the query by clicking the Execute button in the toolbar, as we did earlier.

The Results pane is populated by Analysis Services, and the dataset partially shown in Illustration 16 appears.


Illustration 16: Results Dataset (Partial View) – Level Expression at Work ...

Country United States is, indeed, drilled down to child Cities containing sales values, whose individual sales totals make up the summary United States total for each Calendar Year. As we noted to be the case with the Set Expression in the ROWS axis specification in earlier examples, the added Level Expression can also be subjected to parameterization within a reporting (or other) application, for far-reaching capabilities with regard to manipulation of the supporting dataset of a target report containing the DrillDownLevel() function under consideration.

The report authors state that their immediate goals have been met. We agree to return at a later time to demonstrate approaches to implement the DrillDownLevel() function in Reporting Services to leverage MDX to support interactive drilldown by organizational information consumers.

14.  Select File --> Save MDX040-002-2.mdx to save our work.

15.  Select File --> Exit to leave the SQL Server Management Studio, when ready.

Summary ...

In this article, we continued our extended examination of the MDX surrounding drilling up and down within our Analysis Services cubes, focusing upon the DrillDownLevel() function. We noted that the DrillDownLevel() function can be leveraged within and among the various "layers" of the Microsoft integrated Business Intelligence solution to support sophisticated presentations and features. We introduced the function, commenting upon its operation and touching upon examples of effects that we can employ it to deliver to empower information consumers to maneuver between summarized and detailed levels of data.

As a part of our examination of the DrillDownLevel() function, we commented upon its operation and touched upon the "extended" datasets we can deliver using the function with a specified Set Expression and optional Level Expression (as well as discussing its default behavior when no Level Expression is specified). We also discussed the Index option, and how it supports further control over drilldown between levels. Next, we examined the syntax involved with DrillDownLevel(), and then undertook a couple of illustrative practice examples within which we met hypothetical business requirements with the function, generating queries that capitalized on its primary features. Further, we discussed points within our query where we might consider the insertion of parameterization in a reporting application (or other consumer application), such as Reporting Services, to leverage the function to support drilldown in an ad hoc manner. Throughout our practice session, we briefly discussed the results datasets we obtained from each of the queries we constructed.

» See All Articles by Columnist William E. Pearson, III

Discuss this article in the MSSQL Server 2000 Analysis Services and MDX Topics Forum.



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM