Time Intelligence Wizard script shortcomings

This is a question very much like one posed at http://spaces.msn.com/members/cwebbbi/

Basically, the script generated by the Time Intelligence Wizard only works for one level of a hierarchy.I would like to know the best way to correct this. In my case several time dimensions are present - this means a short and simple answer is preferable as many scripts must be updated.

I will list a couple scenarios using AdventureWorks and their proposed solution below, I welcome comments, especially how I could combine the multiple scripts in the solution for scenario 2:

Scenario 1 - Year to Date

The BIDS generated script is below:

Create Member CurrentCube.[Ship Date].[Fiscal Ship Date Calculations].

[Year to Date] AS "NA" ;

Scope(

{

[Measures].[Internet Sales Amount]

}

);

( [Ship Date].[Fiscal Ship Date Calculations].[Year to Date],

[Ship Date].[Fiscal Year].[Fiscal Year].Members ) =

Aggregate(

{ [Ship Date].[Fiscal Ship Date Calculations].DefaultMember } *

PeriodsToDate(

[Ship Date].[Fiscal].[Fiscal Year],

[Ship Date].[Fiscal].CurrentMember

)

) ;

End Scope ;

This only worked at the year level, a solution is below but it only works because year is the top level of the hierarchy.

Create Member CurrentCube.[Ship Date].[Fiscal Ship Date Calculations].

[Year to Date] AS "NA" ;

Scope(

{

[Measures].[Internet Sales Amount]

}

);

( [Ship Date].[Fiscal Ship Date Calculations].[Year to Date],

[Ship Date].[Fiscal].Members ) =

Aggregate(

{ [Ship Date].[Fiscal Ship Date Calculations].DefaultMember } *

PeriodsToDate(

[Ship Date].[Fiscal].[Fiscal Year],

[Ship Date].[Fiscal].CurrentMember

)

) ;

End Scope ;

Scenario 2 - Quarter to Date

The BIDS generated code is very much like that for scenario 1.The solution demanded 3 scripts though as follows:

( [Ship Date].[Fiscal Ship Date Calculations].[Quarter to Date],

[Ship Date].[Fiscal].[Fiscal Quarter].Members) =

Aggregate(

{ [Ship Date].[Fiscal Ship Date Calculations].DefaultMember } *

PeriodsToDate(

[Ship Date].[Fiscal].[Fiscal Quarter],

[Ship Date].[Fiscal].CurrentMember

)) ;

( [Ship Date].[Fiscal Ship Date Calculations].[Quarter to Date],

[Ship Date].[Fiscal].[Date].Members) =

Aggregate(

{ [Ship Date].[Fiscal Ship Date Calculations].DefaultMember } *

PeriodsToDate(

[Ship Date].[Fiscal].[Fiscal Quarter],

[Ship Date].[Fiscal].CurrentMember

)) ;

( [Ship Date].[Fiscal Ship Date Calculations].[Quarter to Date],

[Ship Date].[Fiscal].[Month].Members) =

Aggregate(

{ [Ship Date].[Fiscal Ship Date Calculations].DefaultMember } *

PeriodsToDate(

[Ship Date].[Fiscal].[Fiscal Quarter],

[Ship Date].[Fiscal].CurrentMember

)

) ;

I had tried several ways to combine/simplify these scripts.

Failed Solution 1(ErrorThe Fiscal hierarchy is used more than once in the Crossjoin function.):

( [Ship Date].[Fiscal Ship Date Calculations].[Quarter to Date],

[Ship Date].[Fiscal].[Date].Members,

[Ship Date].[Fiscal].[Month].Members,

[Ship Date].[Fiscal].[Fiscal Quarter].Members) =

Aggregate(

{ [Ship Date].[Fiscal Ship Date Calculations].DefaultMember } *

PeriodsToDate(

[Ship Date].[Fiscal].[Fiscal Quarter],

[Ship Date].[Fiscal].CurrentMember

)) ;

Failed Solution 2(ErrorAn arbitrary shape of the sets is not allowed in the current context.):

( [Ship Date].[Fiscal Ship Date Calculations].[Quarter to Date],

Descendants([Ship Date].[Fiscal].[Fiscal Quarter].Members, , SELF_AND_AFTER)) =

Aggregate(

{ [Ship Date].[Fiscal Ship Date Calculations].DefaultMember } *

PeriodsToDate(

[Ship Date].[Fiscal].[Fiscal Quarter],

[Ship Date].[Fiscal].CurrentMember

)) ;

Can the three scripts be combined?What is the best solution?I want to develop some fairly generic scripts that can be placed at the end of the calculations of a cube to implement many calculated measures that were implemented utilizing a shell dimension in AS2000.I desire to make these scripts as simple as possible.Any help is appreciated.

Thanks,

Dan

[24747 byte] By [DanKitzmann] at [2007-12-19]
# 1
Hi Dan,

My AdventureWorks cube is out of action at the moment so I've not tested this scriptlet, but does the following do what you want?

( [Ship Date].[Fiscal Ship Date Calculations].[Quarter to Date],

[Ship Date].[Date].Members,
[Ship Date].[Fiscal Quarter].[Fiscal Quarter].Members) =

Aggregate(

{ [Ship Date].[Fiscal Ship Date Calculations].DefaultMember } *

PeriodsToDate(

[Ship Date].[Fiscal].[Fiscal Quarter],

[Ship Date].[Fiscal].CurrentMember

)) ;


The idea here is that you scope on the underlying attributes (some of which, confusingly in Adventure Works, are hidden) rather than the user hierarchy levels, and then use combinations of sets on these attribute hierarchies to restrict the scope. So by scoping on [Ship Date].[Date].Members you put the whole of the [Ship Date] dimension in scope: because it is the key attribute of the [Ship Date] dimension, you know that every member on that dimension will exist with either a member on the [Ship Date].[Date].[Date] level or the All Member. Then by scoping on [Ship Date].[Fiscal Quarter].[Fiscal Quarter].Members (note the exclusion of the All Member here!) you restrict the scope to only those members on the dimension that exist with a specific Quarter.

HTH,

Chris

ChrisWebb at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 2
Hi Chris,
Yes, that did work. Thank you very much. Now I do not have to maintain multiple statements when one will do!

Dan

DanKitzmann at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 3

Hi Chris,

I have similar problem here. Since the [Month Over Month Growth %] also only works for single level as well. The codes it generated is as follow:

( [Time].[yr-mth-day Time Calculations].[Month Over Month Growth %],
[Time].[Month].[Month].Members ( 1 ) : Null ) =
(
( [Time].[yr-mth-day Time Calculations].DefaultMember ) -
( [Time].[yr-mth-day Time Calculations].DefaultMember,
ParallelPeriod(
[Time].[yr-mth-day].[Month],
1,
[Time].[yr-mth-day].CurrentMember
)
)
)
/
( [Time].[yr-mth-day Time Calculations].DefaultMember,
ParallelPeriod(
[Time].[yr-mth-day].[Month],
1,
[Time].[yr-mth-day].CurrentMember
)
)

( [Time].[yr-mth-day Time Calculations].[Month Over Month Growth %],
[Time].[Month].[Month].Members ( 0 )
) = Null

I wanna make the [Month Over Month %] for [Month] level and [Day In Month] level at the same time. I'm newbie in this, any ways to accomplish this? Million Thanks !

KJ

KelvinJor at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 4

Please see the following KB article:

http://support.microsoft.com/Default.aspx?kbid=912136

The solution (what Chris mentioned above), is documented there. You need to add the scope on the key attribute to each calculation (on the left hand side of the assignment)

-rob

RobZare at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...
# 5

(some of which, confusingly in Adventure Works, are hidden)

A good question. Why are certain attributes hidden? The reason is that they are built to be the basis of levels in a user hierarchy, and as such, return the specifc member name (e.g., Q! FY 2002, rather than Q1). The root cause of the annoyance in my mind is not being able to see hidden objects within the development environment, as these are often required in calculations. We've remedied this for the next release.

RobZare at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Analysis Services...

SQL Server

Site Classified