简体   繁体   English

按日期MDX过滤结果

[英]MDX filtering results by date

I want to filter results of my query, so it returns values only if date is greater than specified. 我想过滤查询的结果,因此仅当日期大于指定的日期时它才返回值。

I wrote something like that: 我写了这样的东西:

SELECT { [Measures].[Net sales] } ON COLUMNS
    FROM [Sales]
    WHERE ( { [Department].[Department name].&[WRO], [Department].[Department name].&[KAT]},
            {( FILTER([Time].[Date], [Date].CURRENTMEMBER.MEMBER_KEY >= '2015-10-10'))} );

but it does return null. 但它确实返回null。 Without this part with filter() it returns whole [Net sales] . 如果没有带filter()这部分,它将返回整个[Net sales]

Maybe something like this: 也许是这样的:

WITH 
MEMBER [Measures].[Net sales NEW] AS 
   SUM(
     FILTER(
      [Time].[Date].[Date].MEMBERS, 
      [Time].[Date].CURRENTMEMBER.MEMBER_KEY 
          >= 20151010
     )
     , [Measures].[Net sales]
   )
SELECT 
      {
       [Measures].[Net sales]
      ,[Measures].[Net sales NEW] 
      } ON 0
FROM  [Sales]
WHERE {
       [Department].[Department name].&[WRO]
     , [Department].[Department name].&[KAT]
       };

Another approach: 另一种方法:

WITH 
MEMBER [Measures].[Date_key] AS 
      [Time].[Date].CURRENTMEMBER.MEMBER_KEY 
MEMBER [Measures].[Net sales NEW] AS 
   SUM(
      [Time].[Date].[Date].MEMBERS, 
      IIF(
         [Measures].[Date_key] >= 20151010
       , [Measures].[Net sales]
       , NULL
      )
   )
SELECT 
      {
       [Measures].[Net sales]
      ,[Measures].[Net sales NEW] 
      } ON 0
FROM  [Sales]
WHERE {
       [Department].[Department name].&[WRO]
     , [Department].[Department name].&[KAT]
       };

One question: is this definitely the format of your date keys? 一个问题:这肯定是您的日期键的格式吗? '2015-10-10' “2015年10月10日”

A possible visual way to check your keys, against your WHERE slicer, is to have a simpler script something like this: 根据WHERE slicer来检查密钥的一种可能的可视方法是使用一个更简单的脚本,如下所示:

WITH 
MEMBER [Measures].[Date_key] AS 
      [Time].[Date].CURRENTMEMBER.MEMBER_KEY 
SELECT 
      [Measures].[Date_key] ON 0
      [Time].[Date].[Date].MEMBERS ON 1
FROM  [Sales]
WHERE {
       [Department].[Department name].&[WRO]
     , [Department].[Department name].&[KAT]
      };

Unsure what is wrong with the above - I willneed to test tomorrow against the AdvWrks cube. 不确定上面的问题是什么-我明天需要针对AdvWrks多维数据集进行测试。

Again another approach might be: 同样,另一种方法可能是:

SELECT 
      [Measures].[Net sales] } ON 0
FROM  [Sales]
WHERE ( 
         { [Department].[Department name].&[WRO]
         , [Department].[Department name].&[KAT] }
         , {[Time].[Date].[Date].&[10 Oct 2015]:null} 
      );

note: you need to change 10 Oct 2015 to the formatting in your cube & 10 Oct 2015 must be a date that exists in the cube. 注意:您需要将10 Oct 2015更改为多维数据集中的格式,并且10 Oct 2015必须为多维数据集中存在的日期。

try this: 尝试这个:

SELECT { [Measures].[Net sales] } ON COLUMNS
FROM [Sales]
WHERE ( { [Department].[Department name].&[WRO], [Department].[Department name].&[KAT]},
       {( FILTER([Time].[Date], [Date].CURRENTMEMBER.MEMBER_KEY > '2015-10-10'))} );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM