Microsoft KB Archive/304529

= INF: MDX: How to Test for the Top Most Level in a Hierarchy =

Article ID: 304529

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft SQL Server 2000 Analysis Services
 * Microsoft SQL Server OLAP Services

-



This article was previously published under Q304529



SUMMARY
When you traverse a dimension through a Multidimensional Expressions (MDX), you may have to determine if you are at the top most level of the hierarchy. This article shows you four MDX expressions that allow you to find out if you are at the top most level of the hierarchy.



MORE INFORMATION
The examples print the word &quot;Top&quot; next to the All Promotions member and &quot;Not Top&quot; next the rest of the members, so that you can see which member is on the top most level.

The following two MDX expressions use the IIF function to test if you are at the top level. These expressions work regardless if there is a (All) level in the dimension.

with member measures.test as'iif ([Promotions].CurrentMember.Parent is null,&quot;Top&quot;,&quot;Not Top&quot;)'

Select {[Measures].test} on columns, [Promotions].members on rows from sales -or- with member measures.test as'iif ([Promotions].CurrentMember.Level.Ordinal = 0,&quot;Top&quot;,&quot;Not Top&quot;)'

Select {[Measures].test} on columns, [Promotions].members on rows from sales

If your dimension has an (All) level, you can test explicitly for the top level. For example: with member measures.test as'iif ([Promotions].CurrentMember.level.name = &quot;(All)&quot;,&quot;Top&quot;,&quot;Not Top&quot;)'

Select {[Measures].test} on columns, [Promotions].members on rows from sales However, it would be better to compare the objects by using the IS comparison operator: with member measures.test as'iif ([Promotions].CurrentMember.Level is [Promotions].[(All)],&quot;Top&quot;,&quot;Not Top&quot;)'

Select {[Measures].test} on columns, [Promotions].members on rows from sales NOTE: It is always better to compare objects such as Null or [Promotions].[(All)] by using the IS operator rather than comparing two strings. Comparing objects is faster and the equal (=) operator for string comparison is case sensitive and less flexible.

Additional query words: MDX OLAP BIHOWTO

Keywords: kbinfo KB304529

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.