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
$60.99
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
$32.99 $47.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Tomislav Piasevoli Profile Icon Li
Arrow right icon
$60.99
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
$32.99 $47.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$32.99 $47.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

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
$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 $ 182.97
MDX with Microsoft SQL Server 2016 Analysis Services Cookbook
$60.99
SQL Server 2016 Reporting Services Cookbook
$60.99
Tabular Modeling with SQL Server 2016 Analysis Services Cookbook
$60.99
Total $ 182.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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela