Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
MDX with Microsoft SQL Server 2016 Analysis Services Cookbook
MDX with Microsoft SQL Server 2016 Analysis Services Cookbook

MDX with Microsoft SQL Server 2016 Analysis Services Cookbook: Over 70 practical recipes to analyze multi-dimensional data in SQL Server 2016 Analysis Services cubes , Third Edition

Arrow left icon
Profile Icon Tomislav Piasevoli Profile Icon Li
Arrow right icon
€24.99 €36.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (3 Ratings)
eBook Nov 2016 586 pages 3rd Edition
eBook
€24.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Tomislav Piasevoli Profile Icon Li
Arrow right icon
€24.99 €36.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (3 Ratings)
eBook Nov 2016 586 pages 3rd Edition
eBook
€24.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€24.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.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 Microsoft SQL Server 2016 Analysis Services Cookbook

Chapter 2. Working with Sets

In this chapter, we will cover the following recipes:

  • Implementing the NOT IN set logic
  • Implementing the logical OR on members from different hierarchies
  • Iterating on a set to reduce it
  • Iterating on a set to create a new one
  • Iterating on a set using recursion
  • Performing complex sorts
  • Dissecting and debugging MDX queries
  • Implementing the logical AND on members from the same hierarchy

Introduction

Sets in MDX are collections of tuples with the same dimensionality. As in many other programming languages, the basic logical operations, NOT, AND, and OR, can be applied on them.

When putting two tuples together to form a set, we basically ask for the results that contain any of those tuples. Therefore, sets in MDX naturally imply the OR logic. The first part of the chapter focuses on the challenges and solutions of performing NOT and OR logic operations on sets.

Iterations and recursions can also be performed on sets. The middle part of the chapter concentrates on those actions and the different ways to perform them.

The final part of the chapter explains how to perform complex sorts, how to apply the iteration technique to dissect and debug MDX queries and calculations, and how to perform the logical AND operation in MDX.

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 SQL Server Management Studio (SSMS) and check that you are working on the Adventure Works DW 2016 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...

Implementing the logical OR on members from different hierarchies

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

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

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

Implementing the logical OR on members from different hierarchies

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 these two members together, it would not work. Putting two members from different hierarchies would form a tuple; a tuple implies the logical AND in MDX, not the logical OR.

On the other hand, MDX implies a logical OR. However, we cannot simply put the preceding two members together...

Iterating on a set 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:

Iterating on a set to reduce it

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

Getting ready

Start a new query in SSMS against the Adventure Works DW 2016 database. Then write the following query:

SELECT 
   { [Measures].[Customer Count], 
     [Measures].[Growth in Customer Base] } ON 0, 
   NON EMPTY...

Iterating on a set 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 2016 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 the columns and six countries plus the top level, All Sales Territories, on the rows. The result is shown as follows:

Getting ready

Our goal is to get a set of best months, one for each year. We will use the Generate...

Introduction


Sets in MDX are collections of tuples with the same dimensionality. As in many other programming languages, the basic logical operations, NOT, AND, and OR, can be applied on them.

When putting two tuples together to form a set, we basically ask for the results that contain any of those tuples. Therefore, sets in MDX naturally imply the OR logic. The first part of the chapter focuses on the challenges and solutions of performing NOT and OR logic operations on sets.

Iterations and recursions can also be performed on sets. The middle part of the chapter concentrates on those actions and the different ways to perform them.

The final part of the chapter explains how to perform complex sorts, how to apply the iteration technique to dissect and debug MDX queries and calculations, and how to perform the logical AND operation in MDX.

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 SQL Server Management Studio (SSMS) and check that you are working on the Adventure Works DW 2016 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...

Implementing the logical OR on members from different hierarchies


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

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

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

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 these two members together, it would not work. Putting two members from different hierarchies would form a tuple; a tuple implies the logical AND in MDX, not the logical OR.

On the other hand, MDX implies a logical OR. However, we cannot simply put the preceding...

Iterating on a set 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:

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

Getting ready

Start a new query in SSMS against the Adventure Works DW 2016 database. Then write the following query:

SELECT 
   { [Measures].[Customer Count], 
     [Measures].[Growth in Customer Base] } ON 0, 
...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Updated for SQL Server 2016, this book helps you take advantage of the new MDX commands and the new features introduced in SSAS
  • Perform time-related, context-aware, and business related-calculations with ease to enrich your Business Intelligence solutions
  • Collection of techniques to write flexible and high performing MDX queries in SSAS with carefully structured examples

Description

If you're often faced with MDX challenges, this is a book for you. It will teach you how to solve various real-world business requirements using MDX queries and calculations. Examples in the book introduce an idea or a problem and then guide you through the process of implementing the solution in a step-by-step manner, inform you about the best practices and offer a deep knowledge in terms of how the solution works. Recipes are organized by chapters, each covering a single topic. They start slowly and logically progress to more advanced techniques. In case of complexity, things are broken down. Instead of one, there are series of recipes built one on top of another. This way you are able to see intermediate results and debug potential errors faster. Finally, the cookbook format is here to help you quickly identify the topic of interest and in it a wide range of practical solutions, that is – MDX recipes for your success.

Who is this book for?

This book is for anyone who has been involved in working with multidimensional data. If you are a multidimensional cube developer, a multidimensional database administrator, or a report developer who writes MDX queries to access multidimensional cube, this book will help you. If you are a power cube user or an experienced business analyst, you will also find this book invaluable in your data analysis. This book is for you are interested in doing more data analysis so that the management can make timely and accurate business decisions.

What you will learn

  • Grasp the fundamental MDX concepts, features, and techniques
  • Work with sets
  • Work with Time dimension and create time-aware calculations
  • Make analytical reports compact, concise, and efficient
  • Navigate cubes
  • Master MDX for reporting with Reporting Services (new)
  • Perform business analytics
  • Design efficient cubes and efficient MDX queries
  • Create metadata-driven calculations (new)
  • Capture MDX queries and many other techniques

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 30, 2016
Length: 586 pages
Edition : 3rd
Language : English
ISBN-13 : 9781786467881
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 : Nov 30, 2016
Length: 586 pages
Edition : 3rd
Language : English
ISBN-13 : 9781786467881
Vendor :
Microsoft
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 137.97
MDX with Microsoft SQL Server 2016 Analysis Services Cookbook
€45.99
SQL Server 2016 Reporting Services Cookbook
€45.99
Tabular Modeling with SQL Server 2016 Analysis Services Cookbook
€45.99
Total 137.97 Stars icon
Banner background image

Table of Contents

10 Chapters
1. Elementary MDX Techniques Chevron down icon Chevron up icon
2. Working with Sets Chevron down icon Chevron up icon
3. Working with Time Chevron down icon Chevron up icon
4. Concise Reporting Chevron down icon Chevron up icon
5. Navigation Chevron down icon Chevron up icon
6. MDX for Reporting Chevron down icon Chevron up icon
7. Business Analyses Chevron down icon Chevron up icon
8. When MDX is Not Enough Chevron down icon Chevron up icon
9. Metadata - Driven Calculations Chevron down icon Chevron up icon
10. On the Edge Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(3 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Amazon Customer Aug 29, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent for beginners
Amazon Verified review Amazon
I.W COETZER Jan 08, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have found this book very useful. After struggling for two months with a complex MDX calculation I managed to solve after owning this book for only three days. Well written and good samples.
Amazon Verified review Amazon
Dave Wentzel Dec 07, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was the technical reviewer for this book. I've worked with SSAS for years, but frankly often fumbled around with solutions due to the dearth of really good documentation and blog posts. I've learned MDX, like most, through trial and error...the "error" often only being discovered when my solution wouldn't scale anymore and I was pressed to refactor quickly.If you use SSAS or MDX regularly, and even if you consider yourself an expert, you should still peruse this book. I found a number of recipes that I can incorporate into my daily life. I also found some new ideas and ways to use MDX that I hadn't thought about previously.I liked the real-world examples best. Much better than the contrived code you'll see in many other books.
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.