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
{[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
{[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.