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 Apr 21, 2003

MDX Essentials: Member Functions: More "Family" Functions - Page 8

By William Pearson

Practice

A practice exercise will help us to confirm our grasp of the concepts surrounding .LastSibling. We will design a query to return total Warehouse Cost for each member of the Stores group that is located in the USA, for Q4 of 1997.

10. Type the following query into the Query pane:

-- MDX06-7:  Tutorial Query No. 7
SELECT
{[Time].[Year].[1997].[Q1].LastSibling} ON COLUMNS,
{[Store].[Store Country].[USA].Children} ON ROWS
FROM [Warehouse]
WHERE [Measures].[Warehouse Cost]

11. Select the F5 key to run the query.

The following result dataset appears in the Results pane, after query execution.


Illustration 20: The Query Result Dataset

As requested, we see the Q4 (the last sibling of specified member Q1) totals for the enumerated children of the USA level, within the Store Country level of the Store hierarchy.

To practice further, let's request total Warehouse Cost in the same context as above, but for the months of Q4, with a minor alteration to our query. We'll employ the .Children function again to enumerate the months contained within the fourth quarter, A.K.A. the last sibling of member Q2 - the last of the peer members in its horizontal level of the Time dimension. To reword the objective, we wish to create a column for each month in Q4 and a row item for each child (or state) of the USA level of the Store dimension.

12. Type the following query into the Query pane:

-- MDX06-8:  Tutorial Query No. 8
SELECT
{[Time].[Year].[1997].[Q1].LastSibling.Children} ON COLUMNS,
{[Store].[Store Country].[USA].Children} ON ROWS
FROM [Warehouse]
WHERE [Measures].[Warehouse Cost]

13. Click the Run Query button to execute the query.

The Results pane appears as shown in Illustration 21.


Illustration 21: The Query Results

The query delivers the totals for the enumerated children of the USA Store Country (and thus the States) by months 10, 11, and 12, the children of the fourth quarter, the last sibling of Time dimension member Q1.

 

Next in Our Series ...

In this lesson, MDX Member Functions: More "Family" Functions, we continued the multiple-article Member Functions segment that focuses upon the member functions (and operators, as appropriate) one at a time, contrasting the uses and effects of each. Specifically, we exposed the .FirstChild, .LastChild, .FirstSibling and .LastSibling functions, examining the output returned from each and syntax considerations involved in their use. We practiced putting these additional "family" functions to work through practice exercises, and then reviewed individually the datasets that were returned.

As a part of the lesson, we also examined the effects of using combinations of various "family" functions, and used the NON EMPTY keywords to remove empty intersects from our result sets.

In our next lesson, MDX Member Functions: the Cousin () Function, we will explore a slightly more challenging member function. We will discuss the Cousin() function in detail, illustrate the syntax that is appropriate for its effective use, and then test our understanding of how to leverage this remaining "family" function by undertaking relevant practice exercises. Finally, we will comment on the results we obtain using the Cousin() function, and discuss some of the limitations that are inherent in its use.

» 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