Creating a Calculated Time Periods Hierarchy

倾然丶 夕夏残阳落幕 提交于 2019-12-06 15:27:19

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):

AeroX

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:

  1. Go into your DSV and create a New Named Calculation on your Date table with a name like TimePeriod and set the Value to be something like All Time.

  2. Within your Date dimension create a new Attribute from that Named Calculation and use it to make a Hierarchy.

  3. Make sure the New Attribute is linked to your Day Attribute in the Attribute Relationships tab.

  4. Within your cube, go to the Calculations tab and create a Dummy Calculated Member in the Time Period hierarchy 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...
  1. 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;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!