我正在尝试计算通过SSRS中的参数传递的日期范围的运行总计。我知道我需要使用滞后功能,但我无法做到正确。我尝试使用以下
WITH MEMBER [Measures].[Rolling12Months] AS
SUM(
[Reporting Period].[Fiscal].[Fiscal Month Name].&[1]&[2013] : [Reporting Period].[Fiscal].CURRENTMEMBER,
[Measures].[Amount]
)
答案 0 :(得分:1)
下面的脚本将执行@ whytheq脚本的操作,仅动态。它根据当前成员计算出过去12个月,您可以将其作为切片器传递,或者当您处于设置上下文中时,可能不需要切片器轴。我假设你认为你需要LAG
函数。
WITH SET Last12Months AS
{[Reporting Period].[Fiscal].CURRENTMEMBER.LAG(12) : [Reporting Period].[Fiscal].CURRENTMEMBER}
MEMBER [Measures].[Rolling12Months] AS
SUM(
Last12Months,
[Measures].[Amount]
)
SELECT
[Measures].[Rolling12Months] ON 0
, [Reporting Period].[Fiscal].[Fiscal Month Name].Members ON 1
FROM [YourCubeName]
WHERE [Reporting Period].[Fiscal].[Fiscal Month Name].&[1]&[2014]
//`WHERE` clause can be left out if context is already set.
答案 1 :(得分:0)
您的脚本看起来不错 - 也许只需更改为Aggregate
:
WITH MEMBER [Measures].[Rolling12Months] AS
Aggregate(
[Reporting Period].[Fiscal].[Fiscal Month Name].&[1]&[2013]:[Reporting Period].[Fiscal].CurrentMember,
[Measures].[Amount]
)
所以完整的脚本就像
WITH MEMBER [Measures].[Rolling12Months] AS
Aggregate(
[Reporting Period].[Fiscal].[Fiscal Month Name].&[1]&[2013]:[Reporting Period].[Fiscal].CurrentMember,
[Measures].[Amount]
)
SELECT
{[Measures].[Amount]
, [Measures].[Rolling12Months] } ON 0
, [Reporting Period].[Fiscal].[Fiscal Month Name].Members ON 1
FROM [YourCubeName]