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

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.