MDX MTD 获取月初至今的数据

MDX MTD to get the month to date data

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

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

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

是这样的吗? :

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

如果您使用函数 .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];

这是 returns:

的示例