2

New to MDX and inherited an application using the following to retrieve the last 7 work days.

Note, the actual dates are generated dynamically.

WHERE  ( [DimCalendar].[WorkDayHierarchy].[WorkDate].&[2016-03-25T00:00:00]
: [DimCalendar].[WorkDayHierarchy].[WorkDate].&[2016-03-26T00:00:00].lag(6)
)

I expected it to use the previous 7 work days:

  • 2016-03-17 to 2016-03-25

But instead, it uses future dates

  • 2016-03-25 to latest date in DimCalendar

From what I've read, it's because 2016-03-26 doesn't exist in the hierarchy, so the end range becomes NULL, which explains the future dates..

[WorkDate].&[2016-03-25T00:00:00] : NULL

The problem is the date values are generated dynamically, and don't know in advance which values exist in the hierarchy. I'm not sure how to construct the MDX date range to get the desired results.

I've tried using <= and FILTER but keep getting conversion errors. With plain SQL this would be easy. I could just write:

WHERE [WorkDate] >= '2016-03-17' 
AND   [WorkDate] <= '2016-03-25'

Any ideas what the equivalent filter would be in MDX?

4

1 回答 1

1

快速修复可能是

WHERE([DimCalendar].[WorkDayHierarchy].[WorkDate].&[2016-03-25T00:00:00].lag(7):[DimCalendar].[WorkDayHierarchy].[WorkDate].&[2016-03- 25T00:00:00] )但这只有在过去的日期在层次结构中时才有效,在这种情况下是 2016-03-25。

编辑:基于以下问题

///不使用强名称查询。(不 &)

select {[Measures].[Internet Order Count] }
on columns,
[Date].[Day of Year].[1]:[Date].[Day of Year].[10]
on rows 
from [Adventure Works]

//此查询通过将维度成员值作为度量值进行过滤。

WITH 
MEMBER [Measures].[Data Type] AS 
[Date].[Day of Year].CurrentMember.Properties ("Member_Value",TYPED) 
select {[Measures].[Internet Order Count] }
on columns,    
filter ([Date].[Day of Year].[Day of Year],[Measures].[Data Type]<12)
 on rows 
from [Adventure Works]

//你也可以试试下面的

select 
{[Measures].[Internet Sales Amount],[Measures].[Reseller Sales Amount]} 
on columns, 
filter([Date].[Day of Year].[Day of Year], 
[Date].[Day of Year].currentmember.Properties ("Member_Value",TYPED)
>12 and [Date].[Day of Year].currentmember.Properties ("Member_Value",TYPED)<20) 
on rows 
from 
[Adventure Works]

编辑

//这可能是适合您的确切解决方案

select 
{[Measures].[Internet Sales Amount],[Measures].[Reseller Sales Amount]} 
on columns, 
([Geography].[Country].&[United States]
)
on rows 
from 
[Adventure Works]
where 
filter([Date].[Day of Year].[Day of Year], 
[Date].[Day of Year].currentmember.Properties ("Member_Value",TYPED)
>12 and [Date].[Day of Year].currentmember.Properties ("Member_Value",TYPED)<20) 
于 2018-11-24T21:59:12.357 回答