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
All 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
Arrow up icon
GO TO TOP
MDX with Microsoft SQL Server 2016 Analysis Services Cookbook

You're reading from   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

Arrow left icon
Product type Paperback
Published in Nov 2016
Publisher Packt
ISBN-13 9781786460998
Length 586 pages
Edition 3rd Edition
Arrow right icon
Authors (2):
Arrow left icon
 Li Li
Author Profile Icon Li
Li
Tomislav Piasevoli Tomislav Piasevoli
Author Profile Icon Tomislav Piasevoli
Tomislav Piasevoli
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

MDX with Microsoft SQL Server 2016 Analysis Services Cookbook Third Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Elementary MDX Techniques Working with Sets FREE CHAPTER Working with Time Concise Reporting Navigation MDX for Reporting Business Analyses When MDX is Not Enough Metadata - Driven Calculations On the Edge

Calculating the difference between two dates


This recipe shows how to calculate the difference between two dates. We are going to use promotions as an example, and calculate the time span of a promotion, from the start date to the end date.

Getting ready

Start SQL Server Management Studio and connect to your SSAS 2016 instance. Click on the New Query button and check that the target database is Adventure Works DW 2016. Then execute the following query:

SELECT 
   { [Measures].[Reseller Order Count] } ON 0, 
   { [Promotion].[Start Date].[Start Date].MEMBERS * 
     [Promotion].[End Date].[End Date].MEMBERS } ON 1       
FROM 
   [Adventure Works] 
WHERE 
   ( [Promotion].[Promotion Type].&[Discontinued Product] ) 

The query shows that the Discontinued Product promotion appeared twice with various time spans. Our task is to calculate how many days it lasted each time.

How to do it...

Follow these steps to calculate the difference between two dates:

  1. Add...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images