在MDX中过滤今天的日期

时间:2013-09-20 07:20:29

标签: date filter mdx

您好我正在尝试在MDX查询中添加动态日期过滤器(如今天的日期),但我无法从查询中获得任何结果,是否有人可以帮助检查我的查询有什么问题?

我首先使用指定的日期值测试了MDX查询,查询是

WITH MEMBER [Yesterday] AS VBAMDX.Format(VBAMDX.Now()-1,"MM/dd/yy")

select {[Measures].[Order Root Total], [Measures].[Yesterday]} on columns,
filter ([D Date].[DAY ID].&[09/19/13],
[Measures].[Order Root Total]>0) on rows
from [Root Product Profit and Sales]

返回结果

            Order Root Total    Yesterday
09/19/13    1481.2225483463         09/19/13

然后我尝试了:

WITH MEMBER [Yesterday] AS VBAMDX.Format(VBAMDX.Now()-1,"MM/dd/yy")

select {[Measures].[Order Root Total], [Measures].[Yesterday]} on columns,
filter ([D Date].[DAY ID].&[Yesterday],
[Measures].[Order Root Total]>0) on rows
from [Root Product Profit and Sales]

然后我什么也没有回复..

有人可以帮助我!非常感谢!!!

1 个答案:

答案 0 :(得分:1)

您必须使用StrToMember,因为Yesterday是一项衡量标准,不能直接用于会员名称。我建议在[D Date].[DAY ID]层次结构而不是Measures层次结构中定义昨天:

WITH MEMBER [D Date].[DAY ID].[Yesterday] AS 
     StrToMember('[D Date].[DAY ID].&' + VBAMDX.Format(VBAMDX.Now()-1,"MM/dd/yy") + ']')

select {[Measures].[Order Root Total], [Measures].[Yesterday]} on columns,
filter ([D Date].[DAY ID].[Yesterday],
[Measures].[Order Root Total]>0) on rows
from [Root Product Profit and Sales]