MDX where Date is less than now

柔情痞子 提交于 2019-12-24 12:29:51

问题


This is my code below......

    SELECT 
 {
    [Measures].[ACPPurchaseValue]

  } ON COLUMNS
,(

   [Date].[YYYYMMDD].[YYYYMMDD]

  ) ON ROWS
FROM [Kahuna]
WHERE  
  (
    [Reporting Currency].[reportingCurrency].&[1]
   ,strToSet(@MdxBOSP)
   ,strToSet(@MdxVIPType)
   ,strToSet(@MdxHost)
   ,strToSet(@MdxOperatorName)
  );

How can I say where [Date].[YYYYMMDD].[YYYYMMDD] < getdate()


回答1:


You need to initially create a member, or a single member set, that corresponds to today.

The following looks a little complex but is actually a fairly standard approach - put forward by Tomislav Piasevoli - it is against the AdvWrks dimension Date:

WITH
  MEMBER [Measures].[Key for Today] AS 
    Format
    (
      Now()
     ,'yyyyMMdd'
    ) 
  MEMBER [Measures].[Today string] AS 
    '[Date].[Calendar].[Date].&[' + [Measures].[Key for Today] + ']' 
  SET [Today] AS 
    StrToMember
    (
      [Measures].[Today string]
     ,constrained
    ) 
...

So applying to your situation:

WITH
  MEMBER [Measures].[Key for Today] AS 
    Format
    (
      Now()
     ,'yyyyMMdd'
    ) 
  MEMBER [Measures].[Today string] AS 
    '[Date].[YYYYMMDD].[YYYYMMDD].&[' + [Measures].[Key for Today] + ']' 
  SET [Today] AS 
    StrToMember
    (
      [Measures].[Today string]
     ,constrained
    ) 
SELECT 
   [Measures].[ACPPurchaseValue] ON 0
  ,{null:[Today].item(0).item(0)}  ON 1
FROM [Kahuna]
WHERE  
  (
    [Reporting Currency].[reportingCurrency].&[1]
   ,strToSet(@MdxBOSP)
   ,strToSet(@MdxVIPType)
   ,strToSet(@MdxHost)
   ,strToSet(@MdxOperatorName)
  );

Two other better solutions which could simplify life for everyone:

  1. Do not materialize future dates in your cube

  2. Leave future dates in, but add a custom set called [Today] and a calculated member called today as a child to Date's All member.



来源:https://stackoverflow.com/questions/35479968/mdx-where-date-is-less-than-now

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!