O'Reilly logo

MDX with Microsoft SQL Server 2016 Analysis Services Cookbook - Third Edition by Sherry Li, Tomislav Piasevoli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required