This month, we will examine the LEVEL_NUMBER intrinsic member property. Once we have briefly introduced LEVEL_NUMBER, we will employ the member property, in a hands-on practice session, to meet example business needs for a hypothetical client. The primary focus of this article, like the other articles of this series, is to provide hands-on application of the fundamentals of the Multidimensional Expressions (MDX) language, doing so here specifically within the context of the LEVEL_NUMBER intrinsic member property, in combination with other member properties and MDX functions.
Note: For more information about my MDX Essentials column in general, see the section entitled “About the MDX Essentials Series” that follows the conclusion of this article.
In this lesson, we will examine another intrinsic member property, LEVEL_NUMBER. As many of us are aware, the intrinsic member properties supported by SQL Server 2005 Analysis Services are of two types: context sensitive member properties and non-context sensitive member properties. LEVEL_NUMBER belongs to the latter group of properties. As a general group, intrinsic member properties provide additional information that can be used by applications to enhance the ultimate user experience. Support for the non-context sensitive member properties is the same for all members, regardless of individual context.
The purpose of the LEVEL_NUMBER property is to support the return of the numerical “distance” of a given member from the root of the hierarchy to which the member belongs. LEVEL_NUMBER can be useful in a host of different applications. Moreover, as I have noted to be the case for other functions and properties within the MDX Essentials series, LEVEL_NUMBER allows us to exercise a great deal of presentation “sleight of hand” in working with MDX in Analysis Services, as well as within Reporting Services and various other reporting applications that can access an Analysis Services cube.
The LEVEL_NUMBER property can be leveraged in activities that range from generating simple lists to supporting sophisticated presentations. It can be a particularly effective tool when we need to provide parameter picklist support and the like, as we shall see. We will introduce the function, commenting upon its operation and touching upon examples of effects that we can employ it to deliver. As a part of our discussion, we shall:
- Examine the syntax surrounding the function;
- Undertake illustrative examples of the uses of the function in practice exercises;
- Briefly discuss the results datasets we obtain in the practice examples.
The LEVEL_NUMBER Property
According to the Analysis Services Books Online, the LEVEL_NUMBER property specifies “the distance of the member from the root of the hierarchy.” In Analysis Services, the root level is zero. LEVEL_NUMBER has many applications, including the rather obvious uses with Analysis Services members that are included in the basic definition, as well as its pairing with other MDX functions to leverage its power even further. As an example, as we have seen is the case with many other member properties and functions in earlier articles of this series, LEVEL_NUMBER can also be synergistically combined with the .CurrentMember function; we will see an example of this specific combination within the practice exercises that follow.
We will examine the syntax involved in leveraging the LEVEL_NUMBER property after our customary overview in the Discussion section that follows. Having completed the introduction, we will conduct practice examples within a couple of scenarios, constructed to support hypothetical business needs that illustrate uses for the property. This will afford us an opportunity to explore some of the presentation options that LEVEL_NUMBER can offer the knowledgeable user. Hands-on practice with LEVEL_NUMBER, where we will create expressions that leverage the function, will help us to activate what we learn in the Discussion and Syntax sections that follow.
To restate our initial explanation of its operation, the LEVEL_NUMBER property, when acting upon a member, returns the number (again, with the root level of the containing hierarchy being zero) of the level to which the object - to which it is appended with the period (“.”) delimiter - belongs. LEVEL_NUMBER can be used for a great deal more than the support of simple lists of unique object names, as we have intimated. When we couple it with other functions, we can leverage LEVEL_NUMBER to deliver a wide range of analysis and reporting utility.
As in so many cases with the Microsoft integrated business intelligence solution, consisting of MSSQL Server, Analysis Services and Reporting Services, this function, residing within the Analysis Services layer, can be extended to support capabilities and attributes in the Reporting Services layer. Knowing “where to put the intelligence” among the various layers is critical to optimization, in many scenarios. For more of my observations on this subject, see Multi-Layered Business Intelligence Solutions ... Require Multi-Layered Architects.
The LEVEL_NUMBER property returns, as we have noted, the hierarchical level number within which the specified member is contained, and can be used for querying and display, among other, purposes.
Let’s discuss syntax considerations to further clarify the operation of LEVEL_NUMBER.
Syntactically, anytime we employ the LEVEL_NUMBER property to return the associated level number, the member for which we seek to return the level number is specified to the left of LEVEL_NUMBER. The property takes the object to which it is appended as its argument, and returns, within a string, the unique level name to which the specified object belongs. The general syntax is shown in the following string:
In short, putting LEVEL_NUMBER to work couldn’t be easier. When specifying the property to return the level name containing a member or members, we simply append it to the right of the member(s) under consideration.
As is typically the case with the majority of MDX functions, operators and properties, the LEVEL_NUMBER property can often be best leveraged by combining it with other functions, operators or properties, particularly “relative” functions, to generate lists of names, and so forth, as we shall see in short order.
We will practice some uses of the LEVEL_NUMBER property in the section that follows.