In order to give a nicer Cube browsing experience to end users, I am trying to create a Time Periods hierarchy consisting of Calculated Members.
Currently I have used a Calculated Column in my DSV to create a column with the same value on every row in my Dates table (value is All Time). Then within my Date and Time dimension I have created a single level, single member hierarchy using that Calculated Column, which looks like this:
Now what I have already successfully done is add Time Periods to my Calendar hierarchy with the following calculation:
CREATE MEMBER CURRENTCUBE.[Completion Date].[Calendar].[All].[Last 30 Days]
AS SUM(LastPeriods(30,StrToMember(
"[Completion Date].[Calendar].[Day]."+
"&["+CStr(Year(Now()))+"]&["+CStr(Month(Now()))+"]&["+CStr(Day(Now()))+"]"
))),VISIBLE = 1;
This works as expected on the Calendar hierarchy:
But I want to move these into the new Time Periods hierarchy to keep them nicely separated.
So far I have tried to do this in two different ways:
Changing the destination Hierarchy of the Computed Member. Changing
CREATE MEMBER CURRENTCUBE.[Completion Date].[Calendar].[All].[Last 30 Days]toCREATE MEMBER CURRENTCUBE.[Completion Date].[Time Period].[All].[Last 30 Days].Changing the Visibility of the Calculated Member on the
Calendarhierarchy toVISIBLE = 0and creating a second Caculated Member on theTime Periodshierarchy which references it: (I have tried with and without using theSUM()function)
CREATE MEMBER CURRENTCUBE.[Completion Date].[Time Period].[All].[Last 30 Days]
AS SUM([Completion Date].[Calendar].[All].[Last 30 Days]),
VISIBLE = 1;
But neither of these have worked for me. So my question is, How can I complete what I am trying to achieve?
My end goal is to have a Hierarchy which the user can drag into a pivot table and see the following (but with the Time Periods actually calculated):
I've just created the same this way:
1) Add dummy attribute for unfiltered values with the name 'All Time' (key is int with 0 value)
2) Add 3 empty members
CREATE MEMBER CURRENTCUBE.[Report Date].[Time Period].[All].[Last 30 Days]
AS
null,
VISIBLE = 1;
CREATE MEMBER CURRENTCUBE.[Report Date].[Time Period].[All].[Last 60 Days]
AS
null,
VISIBLE = 1;
CREATE MEMBER CURRENTCUBE.[Report Date].[Time Period].[All].[Last 90 Days]
AS
null,
VISIBLE = 1;
3) Than add scopes (I have another key format):
/* SCOPES */
SCOPE ([Report Date].[Time Period].[All].[Last 30 Days]);
THIS = Sum(LastPeriods(30,StrToMember("[Report Date].[Report Date].[Day].&["+CStr(Format(Now(),"yyyyMMdd"))+"]")));
END SCOPE;
SCOPE ([Report Date].[Time Period].[All].[Last 60 Days]);
THIS = Sum(LastPeriods(60,StrToMember("[Report Date].[Report Date].[Day].&["+CStr(Format(Now(),"yyyyMMdd"))+"]")));
END SCOPE;
SCOPE ([Report Date].[Time Period].[All].[Last 90 Days]);
THIS = Sum(LastPeriods(90,StrToMember("[Report Date].[Report Date].[Day].&["+CStr(Format(Now(),"yyyyMMdd"))+"]")));
END SCOPE;
It works (also add a measure to count members of a level to validate):
Thanks to Alex Peshik's Answer I have managed to get this to work.
Here is the method I have now used to setup a Calculated Time Periods Hierarchy:
Go into your DSV and create a
New Named Calculationon your Date table with a name likeTimePeriodand set the Value to be something likeAll Time.Within your Date dimension create a new Attribute from that Named Calculation and use it to make a Hierarchy.
Make sure the New Attribute is linked to your Day Attribute in the
Attribute Relationshipstab.Within your cube, go to the Calculations tab and create a Dummy Calculated Member in the
Time Periodhierarchy we have made for each time period you want to add:
CREATE MEMBER CURRENTCUBE.[Completion Date].[Time Period].[All].[Last 30 Days]
AS NULL, VISIBLE = 1;
CREATE MEMBER CURRENTCUBE.[Completion Date].[Time Period].[All].[Last 60 Days]
AS NULL, VISIBLE = 1;
CREATE MEMBER CURRENTCUBE.[Completion Date].[Time Period].[All].[Last 90 Days]
AS NULL, VISIBLE = 1;
// etc...
- Now at the bottom of your Calculation you add a Scope for each Dummy Calculation we made in the last step (you will need to change the bit within the
StrToMember()function to match your day attribute Key):
SCOPE ([Completion Date].[Time Period].[All].[Last 30 Days]);
THIS = SUM(LastPeriods(30, StrToMember(
"[Completion Date].[Calendar].[Day]."+
"&["+CStr(Year(Now()))+"]&["+CStr(Month(Now()))+"]&["+CStr(Day(Now()))+"]"
)));
END SCOPE;
SCOPE ([Completion Date].[Time Period].[All].[Last 60 Days]);
THIS = SUM(LastPeriods(60, StrToMember(
"[Completion Date].[Calendar].[Day]."+
"&["+CStr(Year(Now()))+"]&["+CStr(Month(Now()))+"]&["+CStr(Day(Now()))+"]"
)));
END SCOPE;
SCOPE ([Completion Date].[Time Period].[All].[Last 90 Days]);
THIS = SUM(LastPeriods(90, StrToMember(
"[Completion Date].[Calendar].[Day]."+
"&["+CStr(Year(Now()))+"]&["+CStr(Month(Now()))+"]&["+CStr(Day(Now()))+"]"
)));
END SCOPE;
来源:https://stackoverflow.com/questions/28499462/creating-a-calculated-time-periods-hierarchy