2016-12-09 16 views
0

昨年の今月のMTDはどのように計算できますか?以下のクエリは12.2015の[Net Sales Amount]の合計を返しますが、売上高は01.12.2015から09.12.2015(今日)である必要があります。私はあなたが探しているメンバーのHEADを使用する必要があると思う昨年の今月のMTD

SUM(
     MTD(
      ParallelPeriod(
       [Calender].[YMD].[Month], 
       12, 
       [Calender].[YMD].CurrentMember 
      ) 
     ) 
     ,[Measures].[Net Sales Amount] 
    ) 

答えて

1

SUM(
    HEAD(
     ParallelPeriod(
      [Calender].[YMD].[Month], 
      12, 
      [Calender].[YMD].CurrentMember 
     ).CHILDREN, 
    , 9 
    ) 
    ,[Measures].[Net Sales Amount] 
) 

上記は、キューブのデザインに日付が月の子であると仮定しています。

あなたは動的にする必要があります - あなたの立方体の将来の日付はありますか?あなたは将来の日付を持っていない場合は

これは仕事ができる:

WITH 
    MEMBER [Measures].[NumDaysInCurrentMonth] AS 
     Count(
      Descendants(
      TAIL([Date].[Calendar].[Month]).Item(0) //<<<not sure if Item(0) is required 
      ,[Date].[Calendar].[Date] 
      ,SELF 
     ) 
     ) 

あなたは多分未来の日付を持っている場合は、以下:次に

WITH 
    MEMBER [Measures].[NumDaysInCurrentMonth] AS 
     count(
      NONEMPTY(
      Descendants(
       TAIL([Date].[Calendar].[Month]).Item(0) //<<<not sure if Item(0) is required 
       ,[Date].[Calendar].[Date] 
       ,SELF 
      ) 
     ) 
     ) 

上記に供給することができますの1前:

WITH 
    MEMBER [Measures].[NumDaysInCurrentMonth] AS 
    COUNT(
     Descendants(
      TAIL([Date].[Calendar].[Month]).Item(0) //<<<not sure if Item(0) is required 
      ,[Date].[Calendar].[Date] 
      ,SELF 
     ) 
    ) 
    MEMBER [Measures].[PrevYearMTD] AS 
    SUM(
     HEAD(
      ParallelPeriod(
       [Calender].[YMD].[Month], 
       12, 
       [Calender].[YMD].CurrentMember 
      ).CHILDREN, 
     , [Measures].[NumDaysInCurrentMonth] 
     ) 
     ,[Measures].[Net Sales Amount] 
    ) 
関連する問題