我有一个基本的Adventureworks Date Dimension,名为Dates,带有一个名为-CalendarYear的层次结构。我需要创建会给我一个LYFinal聚合和一个LYTD聚合的成员。我已经尝试了总和(YTD与并行期间没有可用。实际上是Sum(YTD和sum)(产生相同的结果,包含整个前一年的聚合。这是代码。
CREATE MEMBER CURRENTCUBE.[Measures].[LYTD_Amount]
AS SUM(YTD(ParallelPeriod([Dates].[-CalendarYear].[Year]
, 1
, [Dates].[-CalendarYear].CurrentMember))
, [Measures].[Actual Detailed Amount]
),
FORMAT_STRING = "$#,##0;-$#,##0",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP =
CREATE MEMBER CURRENTCUBE.[Measures].[Amount LY Final]
AS SUM(ParallelPeriod([Dates].[-CalendarYear].[Year]
, 1
, [Dates].[-CalendarYear].CurrentMember)
, [Measures].[Actual Detailed Amount]
),
FORMAT_STRING = "$#,##0;-$#,##0",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP =
我的日期维度是时间类型。年份和日期设置为年和日。
如果我从查询窗口写一些MDX,YTD功能仍然不限于一年前的LYTD值。这是我的MDX代码(我不打算使用MDX查询数据。用户只需过滤2016年数据,抓住这个衡量标准,它应该提供前一年和之前年初的2015年值)
WITH MEMBER [Measures].[Current YTD] AS
SUM(YTD([Dates].[-CalendarYear].CurrentMember), [Measures].[Actual Detailed Amount])
MEMBER [Measures].[Last YTD] AS
SUM(YTD(ParallelPeriod([Dates].[-CalendarYear].[Year]
, 1
, [Dates].[-CalendarYear].CurrentMember))
, [Measures].[Actual Detailed Amount]
)
SELECT {[Measures].[Current YTD]
, [Measures].[Last YTD]
} ON 0
FROM [Event_Lawson_Dev]
WHERE ([Dates].[-CalendarYear].[Date].&[2016-06-15T00:00:00])
;
--Hardcoded dates to force the YTD
WITH MEMBER [Measures].[Current YTD] AS
SUM({[Dates].[-CalendarYear].[Date].&[2016-01-01T00:00:00]:[Date].[Calendar].[Date].&[2016-06-15T00:00:00]}
, [Measures].[Actual Detailed Amount])
MEMBER [Measures].[Last YTD] AS
SUM( {[Dates].[-CalendarYear].[Date].&[2015-01-01T00:00:00]:[Date].[Calendar].[Date].&[2015-06-15T00:00:00]}
, [Measures].[Actual Detailed Amount]
)
SELECT {[Measures].[Current YTD]
, [Measures].[Last YTD]
} ON 0
FROM [Event_Lawson_Dev]
;