The .LastSibling Function
The .LastSibling function
resembles the .FirstSibling function in its capacity to induce confusion
to those new to MDX: the way that it behaves with the last child of a
given member-parent is the interesting part, and, here again, it may help to
relate to a "family" scenario. Like .FirstSibling, the .LastSibling
function operates within a "horizontal" scope from the
perspective of the hierarchy to which it belongs. It behavior mimics "travel"
within the same level of the hierarchy ("across," again unlike the .FirstChild
and .LastChild functions that we discussed in earlier parts of the
lesson).
Illustration 17 below depicts the relationships under consideration, as shown
below:
Illustration 17: .LastSibling in the Now-Familiar Time
Dimension Hierarchy
The possibly confusing characteristic lies in the fact that
the last child (Q4 in the example illustrated above) also fills
the role of last sibling - it is "last" within the horizontal
level, and is the last sibling of any member residing at the same
level.
To amplify the concept with another illustration, let's
examine the relationships when we consider the last sibling of Q2, as
shown in Illustration 18 below.
Illustration 18: Last Sibling for Q2 is Q4
We see in the illustration above that the last sibling of Q2
is also Q4 - the last member in the level - and the same concepts as
those we discussed for .FirstSibling earlier, just a "different
direction."
Syntax
The .LastSibling function,
like the other functions we have examined in this lesson, is affixed to the right
of the member, as in the following illustration:
<member>.LastSibling
A basic example of the .LastSibling
function in action follows:
SELECT
{[Time].[Year].[1997].[Q2].LastSibling} ON COLUMNS
FROM [Warehouse]
WHERE [Measures].[Warehouse Cost]
The result dataset returned would appear as shown in Illustration
19 below:
Illustration 19: Result Dataset from Using the Example
.LastSibling Function