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:

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

The query shows that the Discontinued Product promotion appeared ...

Get MDX with Microsoft SQL Server 2016 Analysis Services Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.