Logical Functions: IsAncestor(): 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
, MSSQL Server Analysis Services, and the related Books
and Samples.


this lesson, we will expose another logical function which we can use for
testing a member or level at which a cell is being calculated,
the IsAncestor() function. The general purpose of IsAncestor() is
to return whether or not a specified member is an ancestor of another
member we specify. (By “ancestor,” of course, we mean a member from which the
specified member is descended within a dimensional hierarchy.)

The IsAncestor()
function, like other logical functions and operators,
evaluates values and returns a Boolean value. The utility of IsAncestor() becomes
clear when we realize the capability that it gives us to determine the “position,”
together with the relationship to progenitors, of a member within a dimensional
hierarchy. IsAncestor() more specifically allows us to test whether a member
is an ancestor of another member that we specify within the dimension to which
it belongs.

Similar to IsLeaf(), IsSibling(), IsChild(),
IsGeneration(), and other MDX functions, IsAncestor() 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
. In this article, we will concentrate upon IsAncestor() 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 ancestor of another specified member
; the manner in which IsAncestor()
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.

with an introduction to the IsAncestor() function, this lesson will

  • an examination of the syntax surrounding the function;

  • illustrative examples of uses of the function within practice

  • a brief discussion of the MDX results obtained within each of the
    practice examples.

The IsAncestor() Function


According to the Books
, the IsAncestor() function “returns whether a specified
member is an ancestor 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 an ancestor of the second specified member
(the “secondary member expression”); otherwise IsAncestor() returns
False.” In its capacity, as a logical function, to “test” the nature /
status of a member, IsAncestor() 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 relationship between members as ancestor
/ descendant.

We will examine in detail the
syntax for the IsAncestor() function after our customary overview in the
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 IsAncestor() can
offer the knowledgeable user. Hands-on practice with IsAncestor(), where
we will create queries that employ the function, will help us to activate what
we have learned in the Discussion and Syntax


To restate our initial
description of its operation, IsAncestor() returns “True” if a
specified member expression represents an ancestor of another member (that
is, lies between the secondary member and the top / “All” dimensional level) that
we specify within a given use of the function; otherwise, the function returns
False.” We can use IsAncestor() to apply conditional logic
based upon the location and / or existence of members. As we have noted to be the
case with most MDX functions, pairing IsAncestor() 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.

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


Syntactically, we employ the IsAncestor()
function by specifying the primary member expression (the member which
we are testing as to “ancestor status”) and the secondary member expression (the
member in relation to which we are testing the primary member
) 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
is an ancestor of the secondary member expression
(or, in other words, if the primary member lies somewhere between the secondary
and the “top” of the dimensional hierarchy).

If the member specified by the primary
member expression
is not an ancestor of the secondary
(or if the primary member and the secondary member belong
to different dimensions) a False is returned, as we might expect.

The general syntax is shown in
the following string:

IsAncestor(Primary_Member_Expression, Secondary_Member_Expression)

Employing IsAncestor(), like most
of the MDX logical functions, is, in the mechanical sense, straightforward.
As we have noted, we simply place the primary and secondary member
, 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:

IsAncestor([Geography].[Geography].[State-Province].[South Australia],

returns True for the current
of the Geography dimension / Geography hierarchy for
each of the following:

  • Cloverdale

    • 6105

  • Findon

    • 5023

  • Perth

    • 6006

Each of the listed members is a descendant of South
in the cube, as shown in Illustration 1.

Illustration 1: Descendants of South Australia …

Depending upon the structure of the query (and specifically upon
whether the syntax defining axes, etc., eliminates nulls), if members of other
dimensions, or members of levels higher than South Australia within the Geography
hierarchy, were returned in, say, the row axis of the dataset, their values
would be null.

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

We will practice some uses of the IsAncestor() function
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.

Latest Articles