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

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Rss Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles


Posted Jul 12, 2004

MDX Essentials: Basic Set Functions: Subset Functions: The Subset() Function - Page 4

By William Pearson

13.  Execute the query by clicking the Run Query button in the toolbar.

The Results pane is populated, and the dataset depicted in Illustration 3 appears.

Illustration 3: Result Dataset - Ordered Core Query

14.  Re-save the file as MDX021-2.

15.  Leave the query open for the next step.

We have used the Order() function, with the BDESC keyword in place, to obtain the sorted core dataset that the Marketing department wants to see. This allows the information consumers to narrow even further their requirements for a recurring report on the promotions activity by gender. In our next section, we will use the Subset() function to provide for these narrowed, more informed requirements.

NOTE: For details concerning our use of the Order() function above, see my article Basic Set Functions: The Order() Function.

Limiting the Initial Dataset with the Subset() Function

Having provided the Marketing team with a "big picture" idea of promotions activity from the Sales cube, we have equipped them to ask for data within a narrower scope, to eliminate outliers such as promotions that fall below thresholds of interest for various reasons. For purposes of our practice example, we will say that the Marketing information consumers respond to our sorted results dataset within a short period, as we expected, requesting that we provide the report, exactly as it currently appears, on a monthly basis, but that the No Promotion group be excluded (it is of little value in the current context of specific promotion analysis), and that only the top twelve (on the basis of female patronage) promotions be presented in the recurring report.

There are numerous ways to approach this with MDX functions, but we know that Subset() will handle the requirement, particularly in a scenario where we have a sort in place for the dimension member under examination, females.

Let's use the Subset() function to meet the business requirement with precision.

1.  Within the query we have saved as MDX021-2, replace the top comment line of the query with the following:

-- MDX021-3, Use of Subset() Function within the Ordered Query

2.  Save the query as MDX021-3.

3.  Within the query, click to the far right of "ON COLUMNS," in the following line:

{[Gender].Members} ON COLUMNS,

4.  Press the Enter key a couple of times to create space between the line and the line that follows it.

5.  Type the following into the new line:


6.  Place the cursor to the immediate right of the right curly brace ("}") in the following line of the query:

[Measures].[Unit Sales]), BDESC)} ON ROWS

7.  Type a comma (" , "), a space, and then the following:

1, 12)

then another space.

The Query pane appears as shown in Illustration 4.

Illustration 4: The Query with Subset() Function in Place

Note that we set "1" as «Start», because, conveniently enough, we wish to exclude the "0" position (the No Promotions line item) anyway, based upon the request of the Marketing consumers who have defined the business requirement. We set "12" as the «Count», because the same information consumers have requested that we provide the metrics for the range of the top twelve promotions in the final version of this recurring report.

8.  Execute the query by clicking the Run Query button in the toolbar.

The Results pane is populated, and the dataset shown in Illustration 5 appears.

Illustration 5: Result Dataset - The Subset() Function in Action

9.  Re-save the file as MDX021-3.

We have thus provided the Marketing department with the requested analytical data. Because we have built in, via the Order() function, the automatic sorting on the criteria requested, we can be confident that any future generation of the data via this query will provide the appropriate selection, together with the order that reflects the sort of the core dataset. Should the consumers return with a request to change the number of promotions to which they want to narrow their focus, we can accomplish this with a simple adjustment to the «Count» specification within the Subset() function we have placed into our query.

10.  Close the Sample Application when ready.

Summary ...

This article served as the conclusion of a group of three articles surrounding subset-related functions. We introduced the Subset() function, whose general purpose is to return a specified number of elements in a set, beginning at a point in the set that we designate via the «Start» value, and extending for a range of «Count» tuples. We commented upon the operation of the function, and then examined its syntax.

We undertook a multi-step practice example whereby we created a core query, then limited the results that the query returned through the use of the Subset() function, within the context of meeting an illustrative business requirement. We demonstrated the manner in which the Subset() function uses the «Start» and «Count» values we input to generate the precise results that we wish to obtain. We briefly discussed the results dataset we obtained with the Subset() function, together with other surrounding considerations. Throughout our examination of the Subset() function, we compared and contrasted the Subset() and the Head() and Tail() functions, from the perspective of usage and operation, in order to finely distinguish among them for the particular characteristics we need to meet specific business needs.

» 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

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