获取类型的对象:Microsoft.AnalysisServices.AdomdClient.CellSet

时间:2015-02-17 10:47:44

标签: sql-server-2012 ssas mdx ssms-2012

我在SSMS 2012中运行此查询

SELECT YTD([Date].[Calendar].[Month].&[2003])ON 0 FROM [Adventure Works];

我收到此错误

  

执行查询...获取类型的对象:   Microsoft.AnalysisServices.AdomdClient.CellSet格式。细胞集   由1行和0列组成。完成格式化。执行完成

我想从Cube和aginst中选择最近12个月来展示一些措施。

编辑1:

当我尝试针对其中显示null

之一的指标触发它时
SELECT YTD([Date].[Calendar].[Month].&[2003].[8])ON 0 ,
[Measures].[Internet Sales Amount] on 1
FROM [Adventure Works];

输出是:

enter image description here

我缺乏的地方。有人可以将我重定向到正确的方向

2 个答案:

答案 0 :(得分:2)

让我们先来看看YTD文档 - 它需要成员表达式。你指定[Date].[Calendar].[Month].&[2003] - 这很奇怪,因为我认为有一年= 2003年,而不是一个月。无论如何,如果你想要过去12个月,你应该尝试

select
{
   [Measures].[Total Sales] // for example
} on 0,
{
   Descendants(
               Ancestors(
                          Tail(EXISTING [Date].[Calendar].[Day].members,1).Item(0),
                          [Date].[Calendar].[Year]
                        ) // end ancestors
            ,[Date].[Calendar].[Month]
              ) // end descendants

 }
 on 1
from [YourCube]

现在有点解释。 Tail(EXISTING [Date].[Calendar].[Day].members,1).Item(0)为您提供多维数据集Calendar dimensions中存在的最后日期。你需要几个月,所以剩下两个步骤:

  • 获得此日期的年份
  • 在多维数据集层次结构中存在今年的月份

Ancestors此处用于获取Year成员(第二个参数[Date]。[Calendar]。[Year])。现在我们已经转到年级,所以我们准备好使用Descendants函数来获取所有月份,这将给出与[Year]相关的所有级别成员,这里我们指定[Month]。请检查列出的功能MSDN文档

答案 1 :(得分:2)

试试这个:

SELECT 
  [Measures].[Internet Sales Amount] ON 0
 ,YTD([Date].[Calendar].[Date].&[20070114]) ON 1
FROM [Adventure Works];

它使用我们指定的级别返回年份,即天数:

enter image description here

然后,我们可以使用自定义度量聚合上述内容:

WITH 
  MEMBER [Date].[Calendar].[YTDtotalTo14jan] AS 
    Aggregate(YTD([Date].[Calendar].[Date].&[20070114])) 
SELECT 
  [Measures].[Internet Sales Amount] ON 0
 ,[Date].[Calendar].[YTDtotalTo14jan] ON 1
FROM [Adventure Works];

看起来你刚刚选择了糟糕的2003年!

要返回过去12个月,请使用Tail功能:

SELECT 
  {} ON 0 //<<add whatever measures you like in here
 ,Tail
  (
    [Date].[Calendar].[Month]
   ,12
  ) ON 1
FROM [Adventure Works];

P.S。我在SSMS

中运行良好
SELECT YTD([Date].[Calendar].[Month].&[2003])ON 0 FROM [Adventure Works];

这不是错误讯息......

  

执行查询...获取类型的对象:   Microsoft.AnalysisServices.AdomdClient.CellSet格式。细胞集   由1行和0列组成。完成格式化。执行完成