使用过滤器限制日期范围

时间:2015-01-21 14:39:58

标签: ssas mdx olap

如果不使用冒号运算符,如何将集合AllDates过滤到05Jan2005到10Jan2006?

WITH 
  SET [AllDates] AS 
    [Date].[Date].[Date].MEMBERS 
  MEMBER [Measures].[DTkey] AS 
    [Date].[Date].CurrentMember.Member_Key 
  MEMBER [Measures].[DTmemValue] AS 
    [Date].[Date].CurrentMember.MemberValue 
  MEMBER [Measures].[DTvalue] AS 
    [Date].[Date].CurrentMember.Value 
SELECT 
  {[Measures].[DTmemValue]} ON 0
 ,Filter
  (
    [AllDates]
   ,
    [Measures].[DTmemValue] > 0
  ) ON 1
FROM [Adventure Works];

2 个答案:

答案 0 :(得分:1)

WITH 
  SET [AllDates] AS 
    [Date].[Date].[Date].MEMBERS 
  MEMBER [Measures].[DTkey] AS 
    [Date].[Date].CurrentMember.Member_Key 
  MEMBER [Measures].[DTmemValue] AS 
    [Date].[Date].CurrentMember.MemberValue 
  MEMBER [Measures].[DTvalue] AS 
    [Date].[Date].CurrentMember.Value 
SELECT 
  {[Measures].[DTmemValue]} ON 0
 ,Filter
  (
    [AllDates]
   ,
    CDate([Measures].[DTmemValue]) > CDate("2006-01-01")
  ) ON 1
FROM [Adventure Works];

可以找到有关MDX过滤的更多详细信息:http://chrish.com.au/blog/filtering-in-mdx/

答案 1 :(得分:1)

我没有Adv Wks但在我的下面测试了它并且效果很好。

这是你要找的吗?

WITH 
  SET [AllDates] AS 
    [Date].[date].[date].members
  MEMBER [Measures].[DTkey] AS 
    [Date].[date].CurrentMember.Member_Key 
  MEMBER [Measures].[DTmemValue] AS 
   [Date].[date].CurrentMember.MemberValue 
  MEMBER [Measures].[DTvalue] AS 
    [Date].[date].CurrentMember.Value 
SELECT 
  {[Measures].[DTmemValue]} ON 0
 ,Filter
  (
    [AllDates]
   ,
   CDate([Measures].[DTmemValue]) >= CDate("01/05/2005") 
   and CDate([Measures].[DTmemValue]) <= CDate("01/10/2006")
  ) ON 1
FROM [Adventure Works];