About the Series ...
This article is a member of the series, MDX Essentials. The series is designed to provide hands-on application of the fundamentals of the Multidimensional Expressions (MDX) language, with each tutorial progressively adding features designed to meet specific real-world needs.
For more information about the series in general, as well as the software and systems requirements for getting the most out of the lessons included, please see my first article, MDX at First Glance: Introduction to MDX Essentials.
Note: Current updates are assumed for MSSQL Server, MSSQL Server Analysis Services, and the related Books Online and Samples.
In this lesson, we will expose another useful member of the MDX toolset, the IsSibling() function. The general purpose of IsSibling(), a logical function, is to return whether or not a member that we specify is the sibling of another member we specify. (By sibling, of course, we mean that the two members share the same parent.)
The IsSibling() function, like other logical functions and operators, evaluates values and returns a Boolean value. The utility of IsSibling() becomes clear when we realize the capability that it gives us to determine the position, together with the parentage, of a member within a dimensional hierarchy. IsSibling() more specifically allows us to test whether the member shares the same parent, and, therefore, occupies a relative position the same hierarchical distance from the parent, as another member that we specify within the dimension to which it belongs.
Similar to IsLeaf(), IsSibling() can best be employed to apply conditional logic within a couple of primary ways: as a component within a calculation, and as a component within a filter expression. In this article, we will concentrate upon IsSibling() from the perspective of its use within a calculation. We will discuss the straightforward purpose of the function, to ascertain (and indicate) whether a member is the sibling of another specified member; the manner in which IsSibling() manages to do this; and ways we can leverage the function to support effective conditional logic to meet various business needs within our own environments.
Along with an introduction to the IsSibling() function, this lesson will include:
- an examination of the syntax surrounding the function;
- illustrative examples of uses of the function within practice exercises;
- a brief discussion of the MDX results obtained within each of the practice examples.
The IsSibling() Function
According to the Books Online, the IsSibling() function returns whether a specified member is a sibling of another specified member. A Boolean value of True is returned if the member expression to which the function is applied (to which I will refer as the primary member expression throughout this article) is a sibling of the second specified member (the secondary member expression); otherwise IsSibling() returns False. In its capacity, as a logical function, to test the nature / status of a member, IsSibling() is often employed in conjunction with the IIF function to conditionally drive the return of data, such as a member or members, or values, based upon the nature / status of members as siblings.
We will examine in detail the syntax for the IsSibling() function after our customary overview in the Discussion section that follows. Following that, we will conduct practice examples within a couple of scenarios, constructed to support simple, hypothetical business needs that illustrate a use for the function. This will afford us an opportunity to explore some the basic options that IsSibling() can offer the knowledgeable user. Hands-on practice with IsSibling(), where we will create queries that employ the function, will help us to activate what we have learned in the Discussion and Syntax sections.
To restate our initial description of its operation, IsSibling() returns True if a specified member expression represents a sibling of (that is, shares a parent with) another member that we specify within a given use of the function; otherwise, the function returns False. We can use IsSibling() to apply conditional logic based upon the location or existence of members. As we have noted to be the case with most MDX functions, pairing the IsSibling() function with other MDX functions can help us to leverage its power much further than we might in an attempt to use it in standalone fashion.
Lets look at syntax specifics to further clarify the operation of IsSibling() .
Syntactically, we employ the IsSibling() function by specifying the primary member expression (the member we are testing as to sibling status) and the secondary member expression (the member against which we are testing the primary member expression) within parentheses to the immediate right of the function. The function takes the member expressions thus appended to it as its arguments, and returns True if the member denoted by the primary member expression is a sibling of the secondary member expression (or, in other words, if the primary member shares the same parent as the secondary member).
If the member specified by the primary member expression is not a sibling of the secondary member (or if the primary member has a different parent than the secondary member) a False is returned, as we might expect.
The general syntax is shown in the following string:
Employing IsSibling() is, in itself, straightforward. As we have noted, we simply place the primary and secondary member expressions, respectively, in the parentheses to the right of the function. As an example, within a query executed against the sample Adventure Works cube, for the dimension named Geography (with a hierarchy of the same name), the following pseudo-expression:
[Geography].[Geography].[Country].[United States] )
Returns True for the current member of the Geography dimension / Geography hierarchy for each of the following:
- United Kingdom
- United States
We note that the primary member appears, having been treated within MDX as its own sibling.
Depending upon the structure of the query (and specifically upon whether the syntax defining axes, etc., eliminates nulls), if members of levels subordinate to the Country level, within the Geography hierarchy, were returned in, say, the row axis of the dataset, their values would be null.
NOTE: For information on several of the relative functions, of which .CURRENTMEMBER is an example, see my article MDX Member Functions: "Relative" Member Functions, within the Database Journal MDX Essentials series.
We will practice some uses of the IsSibling() function in the section that follows.