只是试图将问题模仿为 ssms 中的 mdx 查询,它可以工作。我如何应用我的立方体计算:
with
set [DateRange] as ( { ParallelPeriod([Date].[Year - Quarter - Month - Date].[Date],
364,
Descendants( [Date].[Year - Quarter - Month - Date].[Year].&[2013] , [Date].[Year - Quarter - Month - Date].[Date]).item(0)
) :
Parallelperiod ([Date].[Year - Quarter - Month - Date].[Date],
364,
Descendants( [Date].[Year - Quarter - Month - Date].[Year].&[2013] , [Date].[Year - Quarter - Month - Date].[Date]).item((Descendants(
[Date].[Year - Quarter - Month - Date].[Year].&[2013] , [Date].[Year - Quarter - Month - Date].[Date])).Count - 1))})
Select {
[Measures].[Turnover]
} on Columns,
non empty
(
[DateRange]
) on Rows
from [Sales Cube]
以下结果:
Turnover Net
03.01.2012 642
04.01.2012 665
05.01.2012 633
06.01.2012 730
07.01.2012 761
08.01.2012 531
09.01.2012 422
10.01.2012 488
11.01.2012 518
.
.
.
23.12.2012 618
24.12.2012 174
25.12.2012 137
26.12.2012 536
27.12.2012 981
28.12.2012 1.052
29.12.2012 1.006
30.12.2012 847
31.12.2012 695
01.01.2013 572
所以你看,日期范围是正确的 2012-01-03 - 2013-01-01
在查询中,我将日期和后代设置为最低级别(天),然后生成日期范围。范围的第一个日期 - 364 天和范围的最后一个日期 -364 天以获得正确的日期范围。不幸的是,我不适用于立方体计算:
// ------------------------------------------------------------------------
//
// Comparison Week Day - Date.Calendar
//
// ------------------------------------------------------------------------
SCOPE (
[Date].[Year - Quarter - Month - Date].MEMBERS,
[Date].[Date].MEMBERS );
///////////////////////////////////////////////////////////////////////////////////////
( [Date Calculations Week Day].[ComparisonWD].[Previous Year],
[Date Calculations Week Day].[AggregationWD].Members )
= SUM( [Date Calculations Week Day].[ComparisonWD].DefaultMember,
{ParallelPeriod([Date].[Year - Quarter - Month - Date].[Date], 364, Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Date]).item(0)) :
Parallelperiod ([Date].[Year - Quarter - Month - Date].[Date], 364, Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Date]).item((Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Date])).Count - 1))} );
END SCOPE;