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

Using recursion to calculate cumulative values

This recipe shows how to calculate a cumulative product and sum it using standard range techniques and recursion.

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.

In this example we're going to use the Subcategory hierarchy of the Product dimension. Here's the query we'll start from:

SELECT
{ [Measures].[Gross Profit],
[Measures].[Gross Profit Margin] } ON 0,
{ [Product].[Subcategory].[Subcategory].MEMBERS } ON 1
FROM
[Adventure Works]

Once executed, the query returns 37 product subcategories and their corresponding profits and margins. Our task is to create calculations ...

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