老化报告MDX查询问题?

时间:2015-01-17 07:42:50

标签: sql sql-server reporting-services ssas mdx

以下是我的MDX查询以生成老化报告。我想使用名为SET的名字 在一个计算的措施内。我收到了这个错误:

  

Query(3,1)该函数需要1的元组集表达式   论点。使用了字符串或数字表达式。

这可以解决吗?

WITH 
  SET [Cnt] AS 
    {'FILTER(
          [Cheque Detail Fact Keys].[Cheque Master ID].[Cheque Master ID]
         ,[Measures].[Paid Amt]<>0
       )'
    } 
  SET [x] AS 
    {
      ClosingPeriod
      (
        [Cal Date].[Month].[Month]
       ,[Cal Date].[Month].[All]
      )
    } 
  MEMBER [Measures].[0-30] AS 
    Sum
    (
      [x].Item(0).Lag(1) : [x].Item(0).Lag(0)
     ,Count(Cnt) //[Measures].[Master Count] 
    ) 
  MEMBER [Measures].[31-60] AS 
    Sum
    (
      [x].Item(0).Lag(2) : [x].Item(0).Lag(1)
     ,Count(Cnt) //[Measures].[Master Count] 
    ) 
  MEMBER [Measures].[>60] AS 
    Sum
    (
      NULL : [x].Item(0).Lag(4)
     ,Count(Cnt)  //[Measures].[Master Count] 
    ) 
SELECT 
  {
    [Measures].[0-30]
   ,[Measures].[31-60]
   ,[Measures].[>60]
  } ON 0
 ,{[Customer].[Name].[Name].ALLMEMBERS} ON 1
FROM [My Cube];

3 个答案:

答案 0 :(得分:0)

我认为这只是你脚本的第一部分。你为什么用字符串?尝试删除叛逆者,只需添加.MEMBERS以获得清晰度:

WITH 
  SET [Cnt] AS 
    {FILTER(
          [Cheque Detail Fact Keys].[Cheque Master ID].[Cheque Master ID].MEMBERS
         ,[Measures].[Paid Amt]<>0
       )
    } 
   ...
   ...

错误信息似乎有点神秘,但我相信花括号本身就是一个功能 - 它们将其中的任何成员转换为一个集合。所以你已经有效地写了这个{<some string>},但是花括号期待的东西可以是一个集合。

运行以下AdvWrks脚本时出现相同的错误消息:

WITH 
  SET [Cnt] AS 
    {'FILTER(
          [Date].[Date].[Date].MEMBERS
         ,[Measures].[Internet Sales Amount] > 10000
       )'
    } 
SELECT 
  [Measures].[Internet Sales Amount] ON 0
 ,[Cnt] ON 1
FROM [Adventure Works];

要在以下度量中使用Cnt计数,您可以创建一个度量但我不认为这将是上下文感知的,因为该集合在其他任何事项之前被评估:

WITH 
  SET [Cnt] AS 
    {FILTER(
          [Cheque Detail Fact Keys].[Cheque Master ID].[Cheque Master ID]
         ,[Measures].[Paid Amt]<>0
       )
    } 
  MEMBER [Measures].[Master Count]  AS 
    [Cnt].count
  SET [x] AS 
    {
      ClosingPeriod
      (
        [Cal Date].[Month].[Month]
       ,[Cal Date].[Month].[All]
      )
    } 
  MEMBER [Measures].[0-30] AS 
    Sum
    (
      [x].Item(0).Lag(1) : [x].Item(0).Lag(0)
     ,[Measures].[Master Count] 
    ) 
  MEMBER [Measures].[31-60] AS 
    Sum
    (
      [x].Item(0).Lag(2) : [x].Item(0).Lag(1)
     ,[Measures].[Master Count] 
    ) 
  MEMBER [Measures].[>60] AS 
    Sum
    (
      NULL : [x].Item(0).Lag(4)
     ,[Measures].[Master Count] 
    ) 
SELECT 
  {
    [Measures].[0-30]
   ,[Measures].[31-60]
   ,[Measures].[>60]
  } ON 0
 ,{[Customer].[Name].[Name].ALLMEMBERS} ON 1
FROM [My Cube];

答案 1 :(得分:0)

问题是您正在尝试将字符串传递给集合。您需要首先使用StrToSet函数将字符串转换为集合。另外正如@whytheq所说,你不需要大括号。

尝试替换

WITH 
  SET [Cnt] AS 
    {'FILTER(
          [Cheque Detail Fact Keys].[Cheque Master ID].[Cheque Master ID]
         ,[Measures].[Paid Amt]<>0
       )'
    } 

用这个 - &gt;

WITH 
  SET [Cnt] AS 
    StrToSet('FILTER(
          [Cheque Detail Fact Keys].[Cheque Master ID].[Cheque Master ID]
         ,[Measures].[Paid Amt]<>0
       )'
     )

使用COUNT功能的正确方法是<<SomeSet>>.COUNT COUNT(<<SomeSet>>)

答案 2 :(得分:0)

[Cnt]集看起来很贵......是基于事实表吗?如果是这样,粒度是什么?

也许您可以在DSV中为度量值组的基表添加计算字段(例如,IIF(付费Amt&lt;&gt; 0,1,0)),然后在该字段上创建基于SUM的度量。然后你的查询变成......

WITH  
  SET [x] AS 
    {
      ClosingPeriod
      (
        [Cal Date].[Month].[Month]
       ,[Cal Date].[Month].[All]
      )
    } 
  MEMBER [Measures].[0-30] AS 
    Sum
    (
      [x].Item(0).Lag(1) : [x].Item(0).Lag(0)
     ,[Measures].[NonZero Check Count] 
    ) 
  MEMBER [Measures].[31-60] AS 
    Sum
    (
      [x].Item(0).Lag(2) : [x].Item(0).Lag(1)
     ,[Measures].[NonZero Check Count] 
    ) 
  MEMBER [Measures].[>60] AS 
    Sum
    (
      NULL : [x].Item(0).Lag(4)
     ,[Measures].[NonZero Check Count] 
    ) 
SELECT 
  {
    [Measures].[0-30]
   ,[Measures].[31-60]
   ,[Measures].[>60]
  } ON 0
 ,{[Customer].[Name].[Name].ALLMEMBERS} ON 1
FROM [My Cube];