Scope Problems with MDX Calculated Members
We were recently investigating a problem for a client regarding the use of Scope within MDX calculated members. The code in question was similar to this:
CREATE MEMBER
CURRENTCUBE.[Measures].[Test Measure To Date]
AS "NA", VISIBLE = 1;
Scope([Date].[Calendar].MEMBERS);
[Measures].[Test Measure To Date] =
SUM(NULL:[Date].[Calendar].CurrentMember,
[Measures].[Test Measure]);
End Scope;
Scope([Date].[Fiscal].MEMBERS);
[Measures].[Test Measure To Date] =
SUM(NULL:[Date].[Fiscal].CurrentMember,
[Measures].[Test Measure]);
End Scope;
Essentially the warehouse was providing a transaction table with credits and debits, this calculated measure was supposed to provide the current balance, summing all transactions to date (not just the current year/period etc, but the entire history). Scope is used to enable the calculation to work across two different date hierarchies, calendar and fiscal.
The problem was that even when the [Date].[Calendar] hierarchy was selected, the code still used the fiscal hierarchy to calculate the value.
This is caused by the fact that [Date].[Fiscal].MEMBERS includes the member [Date].[Fiscal].[All]. Consequently, even when the Fiscal hierarchy was not included in the query, its [All] member was effectively still within the scope. Thus the fiscal calculation was overriding the calendar calculation no matter what was selected.
The solution to this is to exclude [All] from the scope, which can be done by changing the code to the following:
CREATE MEMBER
CURRENTCUBE.[Measures].[Test Measure To Date]
AS "NA", VISIBLE = 1;
Scope(DESCENDANTS([Date].[Calendar],,AFTER));
[Measures].[Test Measure To Date] =
SUM(NULL:[Date].[Calendar].CurrentMember,
[Measures].[Test Measure]);
End Scope;
Scope(DESCENDANTS([Date].[Fiscal],,AFTER));
[Measures].[Test Measure To Date] =
SUM(NULL:[Date].[Fiscal].CurrentMember,
[Measures].[Test Measure]);
End Scope;
DESCENDANTS(xxx,,AFTER) is a simple way of identifying every descendent of the hierarchy AFTER the current member, which is [All] when not specified.
Problem solved, Frog-blog out.
Tags: Calculated Member, Cube, MDX, Scope


February 18th, 2010 at 11:32 am
Hi,
ive used the above method in the following context:
- two time dimensions(A, B), one calculated measure
- for time dimension A, calc measure should display its value
- for time dimension B, calc measure should = NULL
- for time dimension A, the calc measure returns the correct values.
- for time dimension B, the descendant levels return NULL. the [All] level however returns the calc measure’s total.
How can I make this NULL also, without breaking the correct functionality as far as dimension A is concerned?
Many thanks,
Peter
February 18th, 2010 at 1:10 pm
Hi Peter
The problem you have is that if time dimension B is not selected as part of a query, it is essentially selecting the [All] level by default. So if you scope the calculation to be null when Time B is [all] then it will always result in null, no matter whether [all] is physically specified or not.
Does that make any sense?… Essentially you will have to allow the calculation to take place for [All], otherwise the calculation can never take place under any circumstances.
Alex