Do you know anyone Scottish?
- Open SQL Server Management Studio
- Connect to the AdventureWorks cube
- Run the following query:
select [Measures].[Internet Sales Amount]
on 0,
[Geography].[Geography].[State-Province].[England].children
on 1
from [Adventure Works] - Scroll down the result set and point out that according to AdventureWorks, Scotland is a city in England.
SQL 2005 Service Manager
SoftArtisans OfficeWriter
Some Time Intelligence Wizard-generated calculations don’t work
/*
Begin Time Intelligence script for the [Date].[Calendar] hierarchy.
*/
[Year to Date] AS "NA" ;
( [Date].[Calendar Date Calculations].[Year to Date],
{
[Measures].[Internet Sales Amount]
},
[Date].[Calendar Year].[Calendar Year].
Aggregate(
{ [Date].[Calendar Date Calculations].DefaultMember } *
PeriodsToDate(
[Date].[Calendar].[Calendar Year],
[Date].[Calendar].CurrentMember
)
) ;
/*
End Time Intelligence script for the [Date].[Calendar] hierarchy.
*/
SELECT
[Measures].[Internet Sales Amount]*
[Date].[Calendar Date Calculations].[Calendar Date Calculations].ALLMEMBERS
ON 0,
[Date].[Calendar].MEMBERS
ON 1
FROM [Adventure Works]
- It should work on the [Date].[Calendar] user hierarchy.
- It should work on any meaningful combination of attribute hierarchies. So, in Adventure Works, this should mean you should not see values when you are looking at the [Date].[Semester of Year] hierarchy on its own, but if you have crossjoined [Date].[Year] with [Date].[Semester of Year] then it does make sense to see YTD values.
- It should somehow work around the mysterious ‘internal error’ messages that started appearing in OWC – but not in my own MDX in SSMS – when I started testing my code.
After an awful lot of head-scratching I came up with the following scriptlet which is the only way I could see to meet the first two criteria properly (I tried to find a simpler approach, believe me) and minimised the appearance of the bug in the third bullet:
/*
Begin Time Intelligence script for the [Date].[Calendar] hierarchy.
*/
Create Member CurrentCube.[Date].[Calendar Date Calculations].[Year to Date] AS "NA" ;
( [Date].[Calendar Date Calculations].[Year to Date],
{
[Measures].[Internet Sales Amount]
}
,
[Date].[Date].[Date].Members
) =
Aggregate(
{ [Date].[Calendar Date Calculations].DefaultMember } *
PeriodsToDate(
[Date].[Calendar].[Calendar Year],
[Date].[Calendar].CurrentMember
)
) ;
SCOPE([Date].[Calendar Date Calculations].[Year to Date], [Measures].[Internet Sales Amount]);
SCOPE([Date].[Calendar Year].[Calendar Year].Members);
THIS=( [Date].[Calendar Date Calculations].[Year to Date],TAIL(EXISTING([Date].[Date].[Date].Members),1).ITEM(0).ITEM(0));
SCOPE([Date].[Calendar Semester].[Calendar Semester].Members);
THIS=( [Date].[Calendar Date Calculations].[Year to Date],TAIL(EXISTING([Date].[Date].[Date].Members),1).ITEM(0).ITEM(0));
SCOPE([Date].[Calendar Quarter].[Calendar Quarter].Members);
THIS=( [Date].[Calendar Date Calculations].[Year to Date],TAIL(EXISTING([Date].[Date].[Date].Members),1).ITEM(0).ITEM(0));
SCOPE([Date].[Month Name].[Month Name].Members);
THIS=( [Date].[Calendar Date Calculations].[Year to Date],TAIL(EXISTING([Date].[Date].[Date].Members),1).ITEM(0).ITEM(0));
END SCOPE;
END SCOPE;
END SCOPE;
END SCOPE;
END SCOPE;
/*
End Time Intelligence script for the [Date].[Calendar] hierarchy.
*/