MDX MTD获取月初至今的数据

时间:2015-04-27 07:55:43

标签: mdx

目前,我需要显示从月的第一天到特定日期的数据。

SUM(MTD([D Time].[calendar].CurrentMember.parent), [Measures].[Wt])

我尝试上面的代码显示在月份的第一天,直到月底... 任何人都可以帮助纠正我的代码?或者我应该使用PeriodToDate

这样的东西? :

     Sum(
     PeriodsToDate(
         OPENINGPERIOD([D Time].[calendar].CurrentMember), 
         [D Time].[calendar].CurrentMember
      ) , [Measures].[Wt] )

1 个答案:

答案 0 :(得分:0)

如果您使用函数.currentmember,那么它假定在WHERE子句或on rowson columns中使用了层次结构:

WITH 
  MEMBER [Measures].X AS 
    Aggregate
    (

         [Date].[Calendar].CurrentMember.Parent.Children(0)
      : 
        [Date].[Calendar].CurrentMember
     ,[Measures].[Internet Order Count]
    ) 
SELECT 
  {
    [Measures].[Internet Order Count]
   ,[Measures].X
  } ON COLUMNS
 ,{[Date].[Calendar].[Month].&[2006]&[8].Children} ON ROWS
FROM [Adventure Works];

这是通过OPENINGPERIOD

WITH 
  MEMBER [Measures].X AS 
    Aggregate
    (
        [Date].[Calendar].CurrentMember.Parent.Children(0)
      : 
        [Date].[Calendar].CurrentMember
     ,[Measures].[Internet Order Count]
    ) 
  MEMBER [Measures].Y AS 
    Aggregate
    (
        OpeningPeriod
        (
          [Date].[Calendar].[Date]
         ,[Date].[Calendar].CurrentMember.Parent
        ).Item(0)
      : 
        [Date].[Calendar].CurrentMember
     ,[Measures].[Internet Order Count]
    ) 
SELECT 
  {
    [Measures].[Internet Order Count]
   ,[Measures].X
   ,[Measures].y
  } ON COLUMNS
 ,{
    [Date].[Calendar].[Month].&[2006]&[8].Children
   ,[Date].[Calendar].[Month].&[2006]&[7].Children
  } ON ROWS
FROM [Adventure Works];

以下是此内容的示例:

enter image description here