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
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (3 Ratings)
Paperback 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
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (3 Ratings)
Paperback 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 a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781786460998
Vendor :
Microsoft
Category :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 30, 2016
Length: 586 pages
Edition : 3rd
Language : English
ISBN-13 : 9781786460998
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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.