SET中的MDX导航无法正常工作(Lag,Lead,PrevMember,...)

时间:2017-09-19 15:00:45

标签: mdx

我的MDX语句出现以下问题。由于where子句,无法访问创建集“[S_PrevDate]”中的上一个元素。计算出的成员“x”返回一个空集。没有where子句,它工作正常。

@Month =“[Date]。[Y-Q-M-D]。[Month]。& [201709]”

WITH
SET [S_PrevDate] AS
    StrToMember(@Month, CONSTRAINED).PrevMember

MEMBER x AS
    SetToStr([S_PrevDate])

SELECT x ON 0 FROM [cube]

WHERE StrToMember(@Month, CONSTRAINED)

事实上,选择另一个月也不起作用。 “x”仍为空:

WITH
SET [S_PrevDate] AS
    [Date].[Y-Q-M-D].[Month].&[201708]    -- August

MEMBER x AS
    SetToStr([S_PrevDate])

SELECT x ON 0 FROM [cube]

WHERE [Date].[Y-Q-M-D].[Month].&[201709]    -- September

我缺少什么或如何解决此问题?该集合将用于相当多的计算,需要在查询范围中创建。

2 个答案:

答案 0 :(得分:0)

真的需要一套吗?试试吧:

WITH    
MEMBER x AS
    SetToStr([Date].[Y-Q-M-D].[Month].&[201708] )

SELECT x ON 0 FROM [cube]

WHERE [Date].[Y-Q-M-D].[Month].&[201709]    -- September

答案 1 :(得分:0)

脚本中的WHERE子句有什么意义? WHERE在mdx脚本的执行顺序中很早就会发生 - 并创建范围。

你有:

WITH
  SET [S_PrevDate] AS
    StrToMember(@Month, CONSTRAINED).PrevMember
MEMBER x AS SetToStr([S_PrevDate])
SELECT x ON 0 
FROM [cube]
WHERE StrToMember(@Month, CONSTRAINED);

我不明白为什么你不能放弃WHERE条款?

WITH
  SET [S_PrevDate] AS
    StrToMember(@Month, CONSTRAINED).PrevMember
MEMBER x AS SetToStr([S_PrevDate])
SELECT x ON 0 
FROM [cube];

这也可能是另一种选择:

WITH
SET [MTH] AS 
    StrToSet("{" + @Month + "}", CONSTRAINED)
SET [S_PrevDate] AS
    [MTH].ITEM(0).PrevMember
MEMBER x AS
    SetToStr([S_PrevDate])
SELECT x ON 0 
FROM [cube];