MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations

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.


We have noted in several articles that, while MDX functions comprise the lion’s share of the MDX Essential series, numerous operators are provided within the language. Of the logical, comparison, set, string, and unary operators provided by MDX, we will examine another logical operator in this article. The IsLeaf() operator, like other logical operators, evaluates values and returns a Boolean value. The utility of IsLeaf() becomes clear when we realize its value in helping us to determine the position of a member within a dimensional hierarchy. IsLeaf() more specifically allows us to test if a member is at leaf level, or at the “bottom” level of the dimension to which it belongs.

In this article, we will concentrate upon the useful IsLeaf() operator, from the perspective of its use within a calculation. We will discuss 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.

Along with an introduction to the IsLeaf() operator, this lesson will include:

  • an examination of the 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


According to the Books Online, the IsLeaf() operator “returns a value whether or not 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 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.

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.


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.

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


Syntactically, we employ the IsLeaf() operator by specifying 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, 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 in the section that follows.

William Pearson
William Pearson
Bill has been working with computers since before becoming a "big eight" CPA, after which he carried his growing information systems knowledge into management accounting, internal auditing, and various capacities of controllership. Bill entered the world of databases and financial systems when he became a consultant for CODA-Financials, a U.K. - based software company that hired only CPA's as application consultants to implement and maintain its integrated financial database - one of the most conceptually powerful, even in his current assessment, to have emerged. At CODA Bill deployed financial databases and business intelligence systems for many global clients. Working with SQL Server, Oracle, Sybase and Informix, and focusing on MSSQL Server, Bill created Island Technologies Inc. in 1997, and has developed a large and diverse customer base over the years since. Bill's background as a CPA, Internal Auditor and Management Accountant enable him to provide value to clients as a liaison between Accounting / Finance and Information Services. Moreover, as a Certified Information Technology Professional (CITP) - a Certified Public Accountant recognized for his or her unique ability to provide business insight by leveraging knowledge of information relationships and supporting technologies - Bill offers his clients the CPA's perspective and ability to understand the complicated business implications and risks associated with technology. From this perspective, he helps them to effectively manage information while ensuring the data's reliability, security, accessibility and relevance. Bill has implemented enterprise business intelligence systems over the years for many Fortune 500 companies, focusing his practice (since the advent of MSSQL Server 2000) upon the integrated Microsoft business intelligence solution. He leverages his years of experience with other enterprise OLAP and reporting applications (Cognos, Business Objects, Crystal, and others) in regular conversions of these once-dominant applications to the Microsoft BI stack. Bill believes it is easier to teach technical skills to people with non-technical training than vice-versa, and he constantly seeks ways to graft new technology into the Accounting and Finance arenas. Bill was awarded Microsoft SQL Server MVP in 2009. Hobbies include advanced literature studies and occasional lectures, with recent concentration upon the works of William Faulkner, Henry James, Marcel Proust, James Joyce, Honoré de Balzac, and Charles Dickens. Other long-time interests have included the exploration of generative music sourced from database architecture.
Get the Free Newsletter!
Subscribe to Cloud Insider for top news, trends & analysis
This email address is invalid.
Get the Free Newsletter!
Subscribe to Cloud Insider for top news, trends & analysis
This email address is invalid.

Latest Articles