O'Reilly logo

MDX with Microsoft SQL Server 2008 R2 Analysis Services: Cookbook by 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're going to use an example with promotions, where we'll calculate the time span of a promotion, how many days it lasted.

Getting ready

Start SQL Server Management Studio and connect to your SSAS 2008 R2 instance. Click on the New Query button and check that the target database is Adventure Works DW 2008R2. Then execute this 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 Dicontinued Product promotion appeared twice ...

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