获取当前语句MDX的当月

时间:2015-11-09 14:17:21

标签: sql-server mdx

让我们说我希望每个商店的当前月份销售额。我会先做一个计算成员:

SELECT
{[Measures].[Total sales]}
ON 0,
{[Organization].[Storename]} ON 1
FROM SALES
WHERE
[Period].[Period].[Month].&[2015]&[11]

要自动将其设为最后一个月,我会做这样的事情:

WITH  MEMBER [Measures].[Full Date] as 'NOW()'
MEMBER [Measures].[What Month] as 'MONTH([Full Date])'
Member [Measures].[What Year] as 'YEAR([Full Date])'

SELECT
{[Measures].[Total sales]}
ON 0,
{[Organization].[Storename]} ON 1
FROM SALES
WHERE
[Period].[Period].[Month].&[What Year]&[What month]

但是,我没有这样做的数据。我做错了什么?我该怎么做?

1 个答案:

答案 0 :(得分:1)

它正在寻找一个名为&[What Year]&[What month]的成员,好像在“月”级别中有一个名字的文字成员。

而是在StrToMember子句中使用WHERE函数。

StrToMember("[Period].[Period].[Month].&[" + FORMAT([Measures].[What Year], "") + "]&["+ FORMAT([Measures].[What Month], "") + "]")