Book Image

MDX with SSAS 2012 Cookbook - Second Edition

Book Image

MDX with SSAS 2012 Cookbook - Second Edition

Overview of this book

MDX is the BI industry standard for multidimensional calculations and queries. Proficiency with this language is essential for the realization of your Analysis Services' full potential. MDX is an elegant and powerful language, and also has a steep learning curve.SQL Server 2012 Analysis Services has introduced a new BISM tabular model and a new formula language, Data Analysis Expressions (DAX). However, for the multi-dimensional model, MDX is still the only query and expression language. For many product developers and report developers, MDX is the preferred language for both the tabular model and multi-dimensional model. MDX with SSAS 2012 Cookbook is a must-have book for anyone who wants to be proficient in the MDX language and to enhance their business intelligence solutions.MDX with SSAS 2012 Cookbook is packed with immediately usable, practical solutions. It starts with elementary techniques that lay the foundation for designing advanced MDX calculations and queries. The discussions after each solution will provide you with a solid foundation and best practices. It covers a broad range of real-world topics and solutions and provides you with learning materials to become proficient in the language.This book will guide you through the hands-on and practical MDX solutions, best practices, and many intricacies that hide within the MDX calculations and queries. We will start by working with sets, creating time-aware, context-aware calculations, and business analytics solutions, through to the techniques of enhancing the cube design when MDX is not enough. We will then move on to capturing MDX generated by SSAS front-ends and using SSAS stored procedures, and we will explore the whole range of MDX solutions for real-world BI projects.  
Table of Contents (16 chapters)
MDX with SSAS 2012 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Microsoft SQL Server Analysis is one of the keystones of Microsoft's Business Intelligence (BI) product strategy. It is the most widely deployed OLAP server around the world. Many organizations, both large and small, have adopted it to provide secure and high-performance access to complex analytics.

MDX (for Multi-Dimensional expressions) is the BI industry standard for multidimensional calculations and queries, and is the most widely accepted software language in multidimensional data warehouse. Proficiency with MDX is essential for any professional who works with multidimensional cubes. MDX is an elegant and powerful language, and also has a steep learning curve.

SQL Server 2012 Analysis Services has introduced a new BISM tabular model and a new formula language, Data Analysis Expressions (DAX). However, for the multi-dimensional model, MDX is still the only query and expression language. For many product developers and report developers, MDX still is and always will be the preferred language for both the tabular model and multi-dimensional model.

Despite its popularity, very few books are dedicated to MDX. MDX-related books often limit their content to explaining the concepts of multidimensional cubes, the MDX language concept and its functions, and other specifics related to working with Analysis Services.

This book presents MDX solutions for business requirements that can be found in the real world of business. You will find best practices, explanations on advanced subjects in full detail, and deep knowledge in every topic. Organized around practical MDX solutions, this book provides a full, in-depth treatment of each topic, sequenced in a logical progression from elementary to advanced techniques.

This book is written in a cookbook format. You can browse through the contents and look for solutions to a particular problem. Each recipe is relatively short and grouped by relevancy, so you can find solutions to related issues in one place. Related recipes are sequenced in a logical progression; you will be able to build up your understanding of the topic incrementally.

This book is designed for both beginners and experts in the MDX language. If you are a beginner, this book is a good place to start. Each recipe provides you with best practices and their underlying rationale, detailed sample scripts, and options you need to know to make good choices. If you are an expert, you will be able to use this book as a reference. Whenever you face a particular challenge, you will be able to find a chapter that is dedicated to the topic.

We hope that you will become confident not only in using the sample MDX queries, but also in creating your own solutions. The moment you start creating your own solutions by combining techniques presented in this book, our goal of teaching through examples is accomplished. We want to hear from you about your journey to MDX proficiency. Feel free to contact me.

What this book covers

Chapter 1, Elementary MDX Techniques, uses some simple examples to demonstrate the fundamental MDX concepts, features, and techniques that are the foundations for our further explorations of the MDX language.

Chapter 2, Working with Sets, focuses on the challenges and solutions of performing the logic operations, NOT, OR, and AND, on Sets.

Chapter 3, Working with Time, presents various time-related functions in MDX language that are designed to work with a special type of dimension called the Time and its typed attributes.

Chapter 4, Concise Reporting, focuses on techniques that you can employ in your project to make analytical reports more compact and concise, and therefore, more efficient.

Chapter 5, Navigation, shows common tasks and techniques related to navigation and data retrieval relative to the current context.

Chapter 6, Business Analytics, focuses on how to perform some of the typical business analysis, such as forecasting, allocating values, and calculating the number of days from last sale date.

Chapter 7, When MDX is Not Enough, discovers that MDX calculations are not always the place to look for solutions. It illustrates several techniques to optimize the query response times with a relatively simple change in cube structure.

Chapter 8, Advanced MDX Topics, contains more advanced MDX topics, such as dealing with parent-child hierarchies and unbalanced hierarchies, getting random samples from a random hierarchy, and complex sorting and iterations.

Chapter 9, On the Edge, presents topics that will expand your horizons, such as clearing cache for performance tuning, executing MDX queries in T-SQL environment, using SSAS Dynamic Management Views (DMVs), drillthrough, and capturing MDX queries using SQL Server Profiler.

What you need for this book

To run the examples in the book the following software will be required:

Database Installation

A full installation of Microsoft SQL Server 2012, or at least the following components are required:

  • SQL Server 2012 engine

  • Analysis Services 2012

  • Microsoft SQL Server management Studio

  • Microsoft SQL Server Data Tools (part of the Microsoft Visual Studio Shell 2010)

We recommend the Developer, Enterprise, or Trial Edition of Microsoft SQL Server. A few examples might not work using the Standard Edition.

To download Microsoft SQL Server 2012 Trial Edition, go to Microsoft SQL Server site http://tinyurl.com/TrialSQLServer.

You can find Microsoft SQL Server 2012 Developer Edition on amazon.com, using the link http://tinyurl.com/DeveloperSQLServer2012.

Sample Adventure Works 2012 Database

Both the relational database file and the multidimensional Adventure Works project files are required:

  • AdventureWorksDW2012_Data.mdf: relational database

  • Adventure Works Multidimensional Models SQL Server 2012—Enterprise Edition: SSAS project files

We recommend the Enterprise Edition of the Adventure Works cube project. To download the installation files, use the following link to go to CodePlex: http://tinyurl.com/AdventureWorks2012

For Creating PivotTable

Microsoft Excel 2007 (or newer) with PivotTable is required.

Most of the examples will work with older versions of Microsoft SQL Server (2005 or 2008 or 2008 R2). However, some of them will need adjustments because the Date dimension in the older versions of the Adventure Works database has a different set of years. To solve that problem simply shift the date-specific parts of the queries few years back in time, for example, turn the year 2006 into the year 2002 and Q3 of the year 2007 to Q3 of 2003.

Who this book is for

This book is for multidimensional cube developers or multidimensional database administrators. It is also for report developers who write MDX queries to access multidimensional cube. If you are a power cube user or an experienced business analyst, you will also find this book invaluable.

In other words, this book is for anyone who has been involved with multidimensional cube. This book is for you if you have found yourself in situations where it is difficult to deliver what your users want and you are interested in getting more information out of your multidimensional cubes.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Alternatively, we could have used the Aggregate() function instead."

A block of code is set as follows:

SELECT
   { [Measures].[Reseller Order Quantity],
     [Measures].[Reseller Order Count] } ON 0,
   NON EMPTY
   { [Date].[Month of Year].MEMBERS } ON 1
FROM
   [Adventure Works]
WHERE
   ( [Promotion].[Promotion Type].&[New Product] )

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

SELECT
   { [Measures].[Reseller Sales Amount] } ON 0,
   { ParallelPeriod( [Geography].[Geography].[Country],
                     2,
                     [Geography].[Geography].[State-Province]
                                .&[CA]&[US] ) } ON 1
FROM
   [Adventure Works]

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "We can verify this by browsing the Geography user hierarchy in the Geography dimension in SQL Server Management Studio".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.