Logical Functions: IsGeneration(): Conditional Logic within Filter Expressions

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.


In Logical
Functions: IsGeneration(): Conditional Logic within Calculations
, another article within my MDX Essentials series, we introduced the IsGeneration() function
from the perspective of its use within a calculation. We discussed the straightforward
purpose of this logical function: IsGeneration() provides us a means of
testing whether or not a specified member exists within a specified generation.
As a part of introducing the function, we noted that the effective use of IsGeneration()
as a testing mechanism is dependent upon a good understanding of the manner
with which generation numbers are assigned within Analysis Services. For
this reason, we overviewed the generation concepts, within our preliminary commentary
surrounding the function, in Logical Functions:
IsGeneration(): Conditional Logic within Calculations

In this article, we will examine IsGeneration(), once again as a
conditional logic modifier, but within the context of a filter.
Combining IsGeneration() 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 enhance our overall awareness of the potential of IsGeneration(). From the
perspective of the use of the IsGeneration() function in combination with Filter(), this article will

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

The IsGeneration() Function


As we related in Logical Functions: IsGeneration(): Conditional Logic
within Calculations
, the Books Online tell
us that the IsGeneration() function “returns true if the member
indicated … is in the generation specified….” Otherwise, the function returns
false. Also, if the member we specify evaluates to an empty member, the IsGeneration()
function returns false. A Boolean value of “True” is returned if the member
to which the function is applied resides within the generation number
specified by the Numeric Expression we provide, and “False” is returned
if it does not (or if the member expression we supply identifies an empty
member). In its capacity, as a logical function, to “test” the nature / status
of a member, IsGeneration() can be 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. Moreover, as we shall see in
this article, IsGeneration() can be employed more directly within a filter
expression we place into the specification of an axis within an MDX query.

We will examine in detail the
syntax for the IsGeneration() function 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
hypothetical business needs that illustrate uses for the function. This will
afford us an opportunity to explore some of the basic options that IsGeneration()
can offer the knowledgeable user. Our current examination will focus upon
the use of IsGeneration() within the context of a filter.
Hands-on practice with IsGeneration(), where we will create queries that
employ the function, will help us to activate what we have learned in the Discussion
and Syntax sections.

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


To restate our initial
description of its operation, IsGeneration() returns “True” if a specified Member Expression is the
number of “steps” specified (by the Numeric Expression) away from the leaf
of the containing hierarchy. Alternatively, “False” is
returned if the specified Member Expression is not the specified
number of steps away, or if the Member Expression evaluates to an empty
member. We can use IsGeneration() 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 IsGeneration() with other MDX
functions can help us to leverage its power beyond what we might otherwise
achieve in attempts to use it in standalone fashion.

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


Let’s review the syntax
involved with employing the IsGeneration() function. We employ IsGeneration()
by specifying the Member Expression (the member which we are testing
as to “generation member status”) and the Numeric Expression (the generation
in relation to which we are testing the Member Expression)
within parentheses to the immediate right of the function. The function takes
the Member Expression and Numeric Expression thus appended as its
arguments, and returns True if the member denoted by the Member
exists within the specified generation number (Numeric
) of the hierarchy within which it resides (or, in other words,
if the Member Expression lies the number of steps specified by the Numeric
from the leaf level of the containing hierarchy).

If the member specified by the Member
is evaluated as an empty member, or if the Member Expression
does not exist within the generation number specified by Numeric
, then a False is returned, as we have noted.

The general syntax is shown in
the following string:

IsGeneration(Member_Expression, Numeric_Expression)

As we noted earlier, employing
IsGeneration() is as straightforward, in the mechanical sense, as
working with most of the MDX logical functions, assuming that we
have an adequate grasp of the meaning of generation, (a topic we
discussed in depth in Logical Functions:
IsGeneration(): Conditional Logic within Calculations
). As we learned, we simply place the Member
and Numeric Expression, 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 Date
(with a hierarchy of Calendar), the following pseudo-expression:


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

  • CY 2001
  • CY 2002
  • CY 2003
  • CY 2004

Each of the listed members is a “resident” of generation
number 4
of the Date.Calendar hierarchy – which appears among the
other levels as annotated in Illustration 1.

Illustration 1: Generation Number 4 among the Other
Generations of the Hierarchy …

information on several of the “relative” functions, of which .CurrentMember
(used in the pseudo-expression above) is an example, see my article MDX
Member Functions: "Relative" Member Functions
within the Database Journal MDX

We will practice some uses of the IsGeneration() function,
within the context of filtering, 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