Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
MDX with SSAS 2012 Cookbook
MDX with SSAS 2012 Cookbook

MDX with SSAS 2012 Cookbook: In this book you'll find 90 clearly written recipes to help developers advance their skills with the demanding but powerful language MDX and SQL Server Analysis Services. All leading to greatly improved business intelligence solutions. , Second Edition

eBook
$9.99 $39.99
Paperback
$65.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

MDX with SSAS 2012 Cookbook

Chapter 2. Working with Sets

In this chapter, we will cover:

  • Implementing the NOT IN set logic

  • Implementing the logical OR on members from different hierarchies

  • Implementing the logical AND on members from the same hierarchy

  • Iterating on a set in order to reduce it

  • Iterating on a set in order to create a new one

  • Iterating on a set using recursion

  • Dissecting and debugging MDX queries

Introduction


Sets are collections of tuples with the same dimensionality. Logical operations, NOT, OR and AND, are performed on sets in MDX. When putting the two tuples together to form a set, we ask for the results that contain a tuple. Therefore, the sets in MDX naturally implies logic OR.

The first part of the chapter focuses on the challenges and solutions of performing logic operations NOT, OR and AND, on sets.

Iterations and recursions can also be performed on sets. The second half of the chapter concentrates on iterations and recursions, and the different ways to perform them. Finally, we will cover how to apply the iteration technique to dissect and debug MDX queries and calculations.

Implementing the NOT IN set logic


There are times when we want to exclude some members from the result. We can perform this operation using a set of members on an axis or using a set of members in a slicer, that is, the WHERE part of an MDX query. This recipe shows how to do the latter, that is, how to exclude some members from a set in a slicer. The principle is the same for any part of an MDX query.

Getting ready

Start a new query in SSMS and check that you're working on the Adventure Works DW 2012 database. Then type in the following query and execute it:

SELECT
   { [Measures].[Reseller Order Count] } ON 0,
   NON EMPTY
   { [Promotion].[Promotion].MEMBERS }
   DIMENSION PROPERTIES
       [Promotion].[Promotion].[Discount Percent] 
   ON 1
FROM
   [Adventure Works]

The preceding query returns 12 promotions and all the top-level promotions on the rows axis. The DIMENSION PROPERTIES keyword is used to get additional information about members – each promotion's discount percent. However, the...

Implementing the logical OR on members from different hierarchies


If we need to slice the data by only black color for products, we would put the Black member in the where clause, such as this:

WHERE
   ( [Product].[Color].&[Black] )

In the Adventure Works DW 2012 database, putting Reseller Order Quantity and Count on the columns, we would get this result:

 

Reseller Order Quantity

Reseller Order Count

All Products

72,013

2,970

Cranksets

1,107

261

Gloves

11,553

991

Helmets

4,447

922

Mountain Bikes

12,771

1,119

Mountain Frames

5,604

736

Road Bikes

14,304

1,237

Road Frames

3,456

769

Shorts

8,946

758

Tights

4,562

470

Wheels

5,263

716

Similarly, to get only the products whose size is XL, we can put the member XL in the slicer as:

WHERE
   ( [Product].[Size Range].&[XL] )

What if we want to get the products whose size is XL in the same result set as the result set for black only?

Somehow, we need to combine the black member with the XL member. Simply by putting...

Implementing the logical AND on members from the same hierarchy


This recipe shows how to implement AND logic using members from the same hierarchy.

In the Adventure Works DW 2012 database, there are two members [New Product] and [Excess Inventory] in the [Promotion Type] hierarchy:

[Promotion].[Promotion Type].&[New Product]
[Promotion].[Promotion Type].&[Excess Inventory]

These two promotion types have reseller orders, but the only two months in which they both have reseller orders are July and August.

The idea is to have a single query that displays the reseller orders, where both of these promotion types occur in the same month. In other words, we want to show the reseller orders for July and August.

Our goal is to somehow combine these two members from the same hierarchy so that we perform logic AND along the [Month of Year] hierarchy on the Date dimension.

Getting ready

Start a new query in SSMS and make sure that you're working on the Adventure Works DW 2012 database.

Our first query...

Iterating on a set in order to reduce it


Iteration is a very natural way of thinking for us humans. We set a starting point, we step into a loop, and we end when a condition is met. While we're looping, we can do whatever we want: check, take, leave, and modify items in that set.

In this recipe, we will start from a result set as shown in the following table, and iterate through the days in each fiscal month to count the number of days for which the growth was positive. By "to reduce", we mean the filtering effect; in our example, we need to "filter out" the days for which the growth was not positive. Our goal is still to only display the fiscal months on ROWS, not the days.

 

Customer Count

Growth in Customer Base

July 2005

31

(null)

August 2005

31

0.00%

September 2005

13

-58.06%

October 2005

27

107.69%

November 2005

32

18.52%

December 2005

39

21.88%

Then we will look at a different approach that takes performance advantage of the block- mode calculation.

Getting ready

Start...

Iterating on a set in order to create a new one


There are situations when we don't want to eliminate certain members from a set, but instead execute for each type of loop. This is done using the GENERATE() function. The GENERATE() function applies a set to each member of another set, and then joins the resulting sets by union. In this recipe we'll show you how to create a new set of members from the existing one.

Getting ready

Let's start a new query in SSMS against the Adventure Works DW 2012 database. Then write the following query:

SELECT
   NON EMPTY
   { [Date].[Calendar].[Calendar Year].MEMBERS *
     [Measures].[Sales Amount] } ON 0,
   NON EMPTY
   { [Sales Territory].[Sales Territory Country].MEMBERS }
   ON 1
FROM
   [Adventure Works]

The query returns four years on columns and six countries plus the top level [All Sales Territories] on rows. The result is shown as follows:

 

CY 2005

CY 2006

CY 2007

CY 2008

 

Sales Amount

Sales Amount

Sales Amount

Sales Amount

All Sales Territories...

Iterating on a set using recursion


Recursion is sometimes the best way to iterate a collection. Why? Because iterations using set functions (including the GENERATE() function) require that we loop through the whole set. But what if that set is big and we only need to find something specific in it? Wouldn't it be great to be able to stop the process when we've found what we wanted? Recursion enables just that – to stop when we're done.

In this recipe we're going to see how to calculate the average of an average using recursion.

Getting ready

To get started, start a new query in SSMS and check that you're working in the right database. Then write the following query:

SELECT
   { [Measures].[Order Count] } ON 0,
   NON EMPTY   
   { Descendants( [Date].[Fiscal Weeks].[All Periods],
                   1 , SELF_AND_BEFORE) } ON 1
FROM
   [Adventure Works]

It returns four fiscal years and their total on top for the Order Count measure. Now let's see how to calculate the average daily value on the week...

Dissecting and debugging MDX queries


When writing a query involving complex calculations, you might have a hard time trying to debug it, in case there is a problem inside the calculation. But there is a way. By breaking complex sets and calculations into smaller pieces and/or by converting those sets and members into strings, we can visually represent the intermediate results and thereby isolate the problematic part of the query.

True, there's no real debugger in the sense that you can pause the calculation process of the query and evaluate the variables. What you can do is to simulate that by concatenating intermediate results into strings for visual verification.

Getting ready

For this recipe we'll use the final query in the previous recipe, Iterating on a set using recursion. We have chosen this as our example because it's a relatively complex calculation and we want to check if we're doing the right thing.

How to do it…

Follow these steps to create a calculated measure that shows the evaluation...

Left arrow icon Right arrow icon

Key benefits

  • A wide range of time-related, context-aware, and business-related calculations
  • Combine MDX with utility dimensions
  • Illustration of techniques to enrich business intelligence solutions, aided by practical, hands-on Cookbook recipes

Description

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.  

Who is this book for?

This book is aimed towards developers. However people experienced with other BI and/or SSAS functions will be able to use this book. If you are a Microsoft SQL Server Analysis Services developer and want to improve your solutions using MDX, then this book is for you. This book is also an essential resource for report developers who need to access the multidimensional cubes through the MDX language. The book assumes you have some basic working knowledge of MDX and a basic understanding of dimensional modelling and cube design.

What you will learn

  • Create time-aware calculations that are relative to the current date
  • Construct context-aware calculations that are relative to members on axes
  • Implement business-related calculations such as forecasting, allocation of values, and ABC analysis
  • Combine MDX with utility dimensions
  • Implement error handling
  • Apply AND, OR, NOT logic
  • Conditionally format your MDX calculations
  • Optimize, dissect, and debug MDX calculations and queries
  • Capture MDX generated by SSAS front-ends
  • Register SSAS-related assemblies and use stored procedures in them

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 26, 2013
Length: 420 pages
Edition : 2nd
Language : English
ISBN-13 : 9781849689618
Vendor :
Microsoft
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Aug 26, 2013
Length: 420 pages
Edition : 2nd
Language : English
ISBN-13 : 9781849689618
Vendor :
Microsoft
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 186.97
SQL Server Analysis Services 2012 Cube Development Cookbook
$65.99
Expert Cube Development with SSAS Multidimensional Models
$54.99
MDX with SSAS 2012 Cookbook
$65.99
Total $ 186.97 Stars icon
Banner background image

Table of Contents

9 Chapters
Elementary MDX Techniques Chevron down icon Chevron up icon
Working with Sets Chevron down icon Chevron up icon
Working with Time Chevron down icon Chevron up icon
Concise Reporting Chevron down icon Chevron up icon
Navigation Chevron down icon Chevron up icon
Business Analytics Chevron down icon Chevron up icon
When MDX is Not Enough Chevron down icon Chevron up icon
Advanced MDX Topics Chevron down icon Chevron up icon
On the Edge Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6
(10 Ratings)
5 star 70%
4 star 20%
3 star 10%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Jun 09, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good
Amazon Verified review Amazon
Desert Fun Nov 30, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a must have. I have struggled trying to find a book with good illustrations and easy to follow samples UNTIL this book! It is written so well that I actually enjoy reading the material. It is a must have for anyone like me who is new to MDX and needs to understand not only what the functions are but how the functions actually work!
Amazon Verified review Amazon
Gerhard Brueckl Dec 19, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is the follower of the "MDX with Microsoft SQL Server 2008R2 Analysis Services Cookbook" originally written by Tomislav Piasevoli. For this second edition Sherry Li joined Tomislav and they combine their in deep knowledge of MDX and Analysis Services to bring the content of the book to an even higher level. The structure of the books is very similar and is again very easy to follow. It starts very simple with basic MDX techniques, evolves to frequently used patterns for e.g. TOP N calculations up to time intelligence calculations. Each single recipe describes a specific real world business scenario and splits it up into 4 sections: Getting ready, How to do it ..., How it works ... and There is more ...Getting ready … explains the general prerequisites and when a given recipe can be appliedHow to do it … describes the basic idea and each single step in detail finally coming up with a solutionHow it works … gives further insights on the elaborated solution and why it works like thatThere is more … is dedicated to those who want to dig deeper into a given recipe/topic and the used techniquesThis structure is what makes this book a “cookbook” – search for your topic and you find all necessary information in one place instead of having to work through several different chapters and topics.One of the things I liked the most about the book is the fact that it is not dedicated to MDX only. It also shows how to solve common problems without using MDX but by doing simple changes to the underlying data model which make calculations simpler and also improve overall performance of the cube. It also features some sections about MDX Script and cube calculations in general which you also barely find in any other book.All in all I would say the book is a good read for all beginners and intermediate MDX developers but also experts will learn some new things too – just as I did!
Amazon Verified review Amazon
hxy0135 NJ Oct 29, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a very advanced MDX book. But if you are a beginner and you are willing to spend time to go over the book a couple of times, it can boost your MDX skill a lot in a short time frame. It offers many very practical examples you can mimic to solve the problems in your daily job projects.I love the book. I bought the first version for SQL 2008 R2. It helped me a lot in my projects and helped me advanced my MDX skill in a very short time. So I bought and read this version for SQL 2012. I feel its explanations on some topics and examples have improved and are clearer. It is very easy to read. Learning by example is an easy and fast way to learn MDX skill. Highly recommend it. A Must have book to a MDX developer!
Amazon Verified review Amazon
Dan English Nov 24, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a definite must have MDX reference book for anyone that is learning or already doing multidimensional Analysis Services development. The information contained in this book goes from elementary to novice to expert. What I like about the cookbook style is the scenario and solution design. Not only are the solutions provided, but it also explains them, which is extremely helpful. The recipes start out with a getting ready section, then explain how to do it, then explain how it actually works, and then wait, 'there's more':) So if you are getting into OLAP development or have been doing it for years, this is a must have book to add to your library.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.