MDX Essentials: Basic Set Functions: The TopCount() Function, Part II

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.

Overview

In this article, we will continue the examination of the TopCount()
function that we began in the previous article of the MDX Essentials
series, Basic
Set Functions: The TopCount() Function, Part I
. Before getting "hands-on"
with
TopCount()
in
our last session, we introduced the function, stating that its highest value lies in the fact
that we can use it as a means for isolating best performers from among potentially
large populations of fellow members. We emphasized that this ranking
capability is a critical need in many data analysis and decision support
scenarios, where we often seek to report upon best performers for various
reasons.

We learned that TopCount() facilitates this ranking
capability, allowing us to sort on the numeric value expression upon
which we wish to focus our analysis. We can direct the function to retrieve
the exact number of "top" members we wish to isolate (say, the "top
ten," or the "top twenty"), for a "custom-fit" approach,
that precisely matches the analysis needs of our own environments.

In
this article, we will extend our examination of the TopCount() function
to include somewhat more sophisticated uses. We will dive right into a couple
of practical scenarios, where we will further evolve our understanding of the
operation of TopCount() through:

  • Defining illustrative business needs as posed to us by
    hypothetical groups of information consumers;

  • Discuss the needs from the perspective of MDX in general, and the
    TopCount() function in particular;

  • Construct queries to meet the expressed requirements using
    combinations of TopCount() and other MDX functions we have explored in
    articles of the series;

  • Discuss the syntax contained within the solutions we construct
    for the information consumers;

  • Briefly discuss the results datasets we obtain in executing the
    MDX queries we construct.

To review an introduction to the TopCount() function
before beginning this article, together with examples of its use in basic
scenarios, see my article Basic Set Functions:
The TopCount() Function, Part I
, a member of the MDX
Essentials
series at Database Journal.

Combining TopCount() with other MDX Functions to Add Sophistication

In our introductory article, we
examined the syntax for the TopCount() function, and then looked at its
behavior, based upon arguments we provided to achieve our ends. We learned
that TopCount() sorts a set we specify by another expression we provide
within the function, thus breaking the natural hierarchy of the set. In
returning "a specified number of items from the topmost members of a
specified set, optionally ordering the set first," we noted, the TopCount()
function is an excellent example of the potential power of MDX.

We learned that we specify
three parameters to TopCount(), a set, a count, and a measure, and that
we can return the number of top performers (or "top anything," in
effect), based upon our input, using the syntax shown in the following string:

TopCount(<< Set >>, << Count >> [,<< Numeric Expression >>])

Sophisticated results can be generated using TopCount()
when we supply well-considered parameters to the <<Set>> and <<Numeric Expression>>
arguments, as we shall see in the practice exercises that follow.

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

Latest Articles