# MDX Operators: The IsLeaf() Operator: Conditional Logic within Filter Expressions

November 6, 2006

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. Current updates are assumed for MSSQL Server, MSSQL Server Analysis Services, and the related Books Online and Samples.

### Overview

In MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations, another article within my MDX Essentials series, we introduced the IsLeaf() operator, from the perspective of its use within a calculation. We discussed the straightforward purpose of the operator, to ascertain whether a member is a leaf-level member of a dimension; the manner in which IsLeaf() manages to do this; and ways we can leverage the operator to support effective conditional logic to meet various business needs within our own environments. For a review of this introductory discussion, see MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations.

In this article, we will examine IsLeaf(), once again as a conditional logic modifier, but within the context of a filter. Combining IsLeaf() with the MDX Filter() function is another way we commonly see it in action in the business environment, and our exposure to the practical aspects of its employment in this way will serve to round out our overall awareness of the potential of IsLeaf(). From the perspective of its use in combination with Filter(), this article will include:

• A review of the general syntax surrounding the operator;
• Illustrative examples of uses of the operator in practice exercises;
• A brief discussion of the MDX results obtained within each of the practice examples.

### The IsLeaf() Operator

#### Introduction

As we related in MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations, the Books Online tell us that the IsLeaf() operator "returns whether a specified member is a leaf member." A Boolean value of "True" is returned if the member expression to which it is applied is a leaf member; otherwise IsLeaf() returns "False." IsLeaf() is often employed in conjunction with the IIF() function (as we confirmed via our hands-on practice session in the article), to conditionally return data, such as a member or members (for example, children of a selected member, if they exist, or the selected member if it has no children), or values. As we shall see in the practice examples that come later, IsLeaf() can also be employed in conjunction with the Filter() function, where it serves up the same "True" value if the member expression to which it is applied represents a leaf member, and "False" if not.

We will examine in detail the syntax for the IsLeaf() operator 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 a hypothetical business need that illustrates a use for the operator. This will afford us an opportunity to explore some of the basic options that IsLeaf() can offer the knowledgeable user. Hands-on practice with IsLeaf(), where we will create queries that employ the function, will help us to activate what we have learned in the Discussion and Syntax sections.

NOTE: For more detail surrounding the Filter() function, see Basic Set Functions: The Filter() Function, a member of my Database Journal MDX Essentials series.

#### Discussion

To restate our initial description of its operation, IsLeaf() returns "True" if a specified member expression represents a leaf (or "level 0") member; otherwise, the operator returns "False." We can use IsLeaf() to apply conditional logic based upon the location or existence of members. As we have noted to be the case with most MDX functions and operators, pairing the IsLeaf() operator with other MDX operators and functions can help us to leverage its power even further. While we exploited a combination with the IIF() function in MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations, we will get some hands-on exposure to the use of IsLeaf() with the MDX Filter() function in the practice section of this article.

Let's look at syntax specifics to further clarify the operation of IsLeaf().

#### Syntax

To review the syntax involved with employing the IsLeaf() operator, we specify the member expression in parentheses to the immediate right of the operator. The operator takes the member expression which is appended to it as its argument, and returns True if the member denoted by the member expression is a leaf member (or, in other words, if the member resides at the lowest (0) level of the dimension). If the member specified by the member expression is not a leaf member (or if the member resides at a dimensional level higher than the "zero," or "bottom," level), a False is returned.

The general syntax is shown in the following string:

`IsLeaf(Member Expression)`

Employing IsLeaf() is, in itself, straightforward. As we have noted, we simply place the member expression under consideration in the parentheses to the right of the operator. As an example, within a query executed against the sample Adventure Works cube, for a dimension named Sales Territory (with a hierarchy of the same name), the following pseudo-expression:

`IsLeaf([Sales Territory].[Sales Territory].CURRENTMEMBER) `

Returns True if the current member of the Sales Territory dimension / Sales Territory hierarchy is at level 0.

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 IsLeaf() operator, focusing on its combination with the Filter() function, in the section that follows,

The Network for Technology Professionals

Search:

## Whitepapers and eBooks

 Microsoft Whitepaper: Top 10 Reasons to Upgrade to Windows Server 2008 R2 Articles: Build a More Agile Business with IBM IBM Articles: Virtualization Delivers a Dynamic Infrastructure Articles: IBM Offers Enhanced Measurement and Management for Energy Usage Articles: IBM Helps Transformation to an Information-Based Enterprise Microsoft Articles: Visual Studio 2010 Adobe Article: Adobe Helps PHP Developers Create Rich Internet Applications Adobe Article: Java Developers Finding a Home at Adobe Flex IBM Articles: A Smarter Business Needs Smarter Technology Intel Xeon Processor Increases Server Efficiency and Capabilities Intel Tech Brief: Automated Energy Efficiency for the Intelligent Enterprise Oracle Whitepapers - Innovation for IT Leaders Avaya Article: Communication-Enabled Mashups--Empowering Both Business Owners and IT Internet.com eBook: IT Manager's Guide to Social Networking Internet.com eBook: Get Ready for Windows 7 Microsoft Article: Expression Web 3--New Features for PHP Developers Whitepapers: Manage Your Business Infrastracture with IBM Whitepaper: Maximize Your Storage Investment with HP Internet.com eBook: Becoming a Better Project Manager Microsoft Article: Stress Free and Efficient Designer/Developer Collaboration MORE WHITEPAPERS, EBOOKS, AND ARTICLES

## Webcasts

 SAP Webcast: Crystal Reports Server--Do More. Spend Less. Webcast: Connecting PHP to Microsoft Technologies Video: Microsoft Partner Program Benefits Video: Windows Azure Debugging Tips SAP BusinessObjects Webcast: Unlock the Power of Reporting with Crystal Reports IBM Webcast: Speed Business Innovation with Reduced Cost and Risk Video: Deploy Applications on Windows Azure MORE WEBCASTS, PODCASTS, AND VIDEOS