情况:我通过在多维数据集中创建空度量并使用范围语句来填充计算,在 SQL Server 2012 SSAS 多维模型中创建了计算度量。(所以我可以在计算中使用度量安全性,如此处所述)
SCOPE [Measures].[C];
THIS = IIF([B]=0,0,[Measures].[A]/[Measures].[B]);
我还进行了时间计算,包括上述计算在内的整个测量组的范围。(如解释here)
我为计算创建空成员:
--YTD Calculations
CREATE MEMBER CURRENTCUBE.[Calender Calculations].[YTD-1] AS NULL;
CREATE MEMBER CURRENTCUBE.[Calender Calculations].[YTD] AS NULL;
-- MOVING ANNUAL TOTAL Calculations
CREATE MEMBER CURRENTCUBE.[Calender Calculations].[MAT-1] AS NULL;
CREATE MEMBER CURRENTCUBE.[Calender Calculations].[MAT] AS NULL;
--SCOPE MEASUREGROUPMEASURES
I scope the measuregroup on which the calculations will be performed:
SCOPE (MeasureGroupMeasures("Sales")
);
Next I scope the time calculations for the different Time Hierarchys:
SCOPE ([Calender].[Jaar].[Jaar].members,[Calender].[Calender ID].members);
--YTD
([Calender Calculations].[YTD]=
Aggregate(
CrossJoin({[Calender Calculations].[Current Period]},
PeriodsToDate(
[Calender].[Month Hierarchy].[Jaar],
[Calender].[Month Hierarchy].CurrentMember))
)
);
--YTD -1
([Calender Calculations].[YTD-1]=
Aggregate(
Crossjoin({[Calender Calculations].[Current Period]},
PeriodsToDate(
[Calender].[Month Hierarchy].[Jaar],
ParallelPeriod(
[Calender].[Month Hierarchy].[Jaar],1,
[Calender].[Month Hierarchy].CurrentMember))
)
));
--MAT
([Calender Calculations].[MAT]=
Aggregate(
CrossJoin({[Calender Calculations].&[Current Period]},
ParallelPeriod([Calender].[Month Hierarchy].[Month],11,[Calender].[Month Hierarchy].CurrentMember) :
[Calender].[Month Hierarchy].CurrentMember
)));
--MAT-1
([Calender Calculations].[MAT-1]=
Aggregate(
CrossJoin({[Calender Calculations].&[Current Period]},
ParallelPeriod([Calender].[Month Hierarchy].[Month],23,[Calender]. [Month Hierarchy].CurrentMember) :
ParallelPeriod([Calender].[Month Hierarchy].[Month],12,[Calender].[Month Hierarchy].CurrentMember)
)));
--SCOPE Calendar END
END SCOPE;
关闭度量组范围
--SCOPE MEASUREGROUPMEASURES END
END SCOPE;
结果:当我使用“基本度量”和“计算度量”查询多维数据集时,时间计算的结果对于基本度量是正确的,但对于“计算度量”C 是不正确的,因为首先计算度量,然后再计算正在完成时间计算,从而汇总结果。
示例:当前月份是 2015 年 4 月 每个月的得分为 5%。YTD 衡量标准给出 20%(1 月、2 月等为 5%),必须为 5%
我的问题:如何更改时间计算或“计算的度量”,以便获得正确的结果?