老化报告 MDX 查询问题?

Aging Report MDX query issue?

下面是我的 MDX 生成老化报告的查询。我想使用命名 SET 在计算的度量中。我收到此错误:

Query (3, 1) The function expects a tuple set expression for the 1 argument. A string or numeric expression was used.

这个可以解决吗?

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];

我认为这只是您脚本的第一部分。你为什么使用字符串?尝试删除撇号并为清楚起见只需添加 .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];

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

尝试替换

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

用这个-->

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

另外 COUNT 函数的正确使用方法是 <<SomeSet>>.COUNT, NOT COUNT(<<SomeSet>>)

[Cnt] 套装看起来很贵...这是基于事实 table 吗?如果有,粒度是多少?

也许您可以在 DSV 中为度量值组的基础 table 添加一个计算字段(例如 IIF(Paid Amt <> 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];