The .FirstSibling
Function
The .FirstSibling
function is a bit more confusing than .FirstChild to some who are new to
MDX, mainly in the way that it works for the first child of a given
member-parent, but it may help again to relate the concept to a "family"
scenario. As we discussed in the introductory section for this article, the .FirstSibling
(as well as the .LastSibling) function operates within a "horizontal"
scope for the hierarchy involved. It effectively "travels" within
the same level of the hierarchy ("across" versus "up and down,"
as it does in the case of the .FirstChild and .LastChild
functions.
Illustration 11 below depicts the relationships between the members and levels
under consideration, as shown below:
Illustration 11: Revisiting the Time Dimension Hierarchy to
Display .FirstSibling
The possibly confusing characteristic lies the fact that the
first child (Q1 in the example illustrated above) also fills the
role of first sibling - it is "first" within the horizontal
level, and is the first sibling of any member residing at the
same level. This is an ordering concept, and becomes straightforward once the
meaning is clear. To amplify the concept with another illustration, let's
examine the relationships when we consider the first sibling of Q3, as
shown in Illustration 12 below.
Illustration 12: First Sibling for Q3 is Q1
We see in the illustration above that the first sibling of Q3
is Q1 - the first member in the level, plain and simple.
Syntax
The .FirstSibling
function is affixed to the right of the member, as in the following
illustration:
<member>.FirstSibling
A basic example of the .FirstSibling
function in action follows:
SELECT
{[Time].[Year].[1997].[Q2].FirstSibling} ON COLUMNS
FROM [Warehouse]
WHERE [Measures].[Units Ordered]
The dataset returned would appear as shown in Illustration
13 below:
Illustration 13: Result Dataset from Using the Example .FirstSibling
Function