如何在MDX查询中计算YTD天数

时间:2015-03-30 08:05:01

标签: mdx ssas-2008

我在MDX下方查询,它为我的每个设备提供了YTD金额,但我想要计算YTD天计算YTD天量。

如何在查询中实现YTD天的计数?

WITH 
  MEMBER [Settlement Date].[Calendar].[CalendarYTD] AS 
    Aggregate
    (
      YTD
      (
        [Settlement Date].[Calendar].[Settlement Calendar Month].&[201412]
      )
    ) 
SELECT 
  [Settlement Date].[Calendar].[CalendarYTD] ON COLUMNS
 ,NON EMPTY 
    [Device].[DeviceID].Children ON ROWS
FROM [cube1]
WHERE 
  [Measures].[amount];

OR

您可以在进行更改时使用AW MDX下方的查询,这些更改会产生与上述查询相同的结果:

WITH 
  MEMBER [Date].[Calendar].[CalendarYTD] AS 
    Aggregate(YTD([Date].[Calendar].[Month].[March 2015])) 
SELECT 
  [Date].[Calendar].[CalendarYTD] ON COLUMNS
 ,[Product].[Category].Children ON ROWS
FROM [Adventure Works]
WHERE 
  [Measures].[Order Quantity];

1 个答案:

答案 0 :(得分:0)

这有点交换,但希望朝着你需要的方向前进:

WITH 
  MEMBER [Date].[Calendar].[CalendarYTD] AS 
    Aggregate(YTD([Date].[Calendar].[Month].[March 2007])) 
  MEMBER [Measures].[DaysCompleteCurrYear] AS 
    Descendants
    (
      YTD([Date].[Calendar].[Month].[March 2007])
     ,[Date].[Calendar].[Date]
     ,SELF
    ).Count 
SELECT 
  {
    [Measures].[DaysCompleteCurrYear]
   ,[Measures].[Order Quantity]
  } ON COLUMNS
 ,[Product].[Category].Children ON ROWS
FROM [Adventure Works]
WHERE 
  [Date].[Calendar].[CalendarYTD];

如果我们将目标月份放入单个成员集中,则会保留家庭关系,我们可以在自定义度量中使用该集合:

WITH 
  SET [targMth] AS 
    {[Date].[Calendar].[Month].[March 2007]} 
  MEMBER [Date].[Calendar].[CalendarYTD] AS 
    Aggregate(YTD([targMth].Item(0).Item(0))) 
  MEMBER [Measures].[DaysCompleteCurrYear] AS 
    Descendants
    (
      YTD([targMth].Item(0).Item(0))
     ,[Date].[Calendar].[Date]
     ,SELF
    ).Count 
SELECT 
  {
    [Measures].[DaysCompleteCurrYear]
   ,[Measures].[Order Quantity]
  } ON COLUMNS
 ,[Product].[Category].Children ON ROWS
FROM [Adventure Works]
WHERE 
  [Date].[Calendar].[CalendarYTD];