聚合的 MDX 错误

MDX error with aggregate

我对 MDX 有以下查询

CREATE 
  MEMBER CURRENTCUBE.[Measures].[Estimating Accuracy Labour Hours] AS 
    Sum
    (
      CASE 
        WHEN 
              (1
              - 
                  [Measures].[Estimation Difference]
                / 
                  Aggregate
                  (
                    [Measures].[Actual Labour Hours]
                   ,[DISTRICTS D].[District]
                   ,[WORK  D].[Work].[Work  Description]
                  )
              )
            * 100
          > 0 
        THEN 
            (1
            - 
                [Measures].[Estimation Difference]
              / 
                Aggregate
                (
                  [Measures].[Actual Labour Hours]
                 ,[DISTRICTS D].[District]
                 ,[WORK  D].[Work].[Work  Description]
                )
            )
          * 100
        ELSE 0
      END
    ) 
   ,VISIBLE = 1 
   ,ASSOCIATED_MEASURE_ = 'WORK F' ; 

我收到以下错误

MdxScript(TEST) (52, 71) Too many arguments were passed to the AGGREGATE function. The maximum argument count for the function is 2.

如何解决?

该错误比大多数 MDX 错误消息更容易理解!

您在此代码段中有三个参数:

Aggregate
   (
         [Measures].[Actual Labour Hours]
        ,[DISTRICTS D].[District]
        ,[WORK  D].[Work].[Work  Description]
   )

这是 MSDN 定义:https://msdn.microsoft.com/en-us/library/ms145524.aspx

Aggregate(Set_Expression [ ,Numeric_Expression ])

按照这个定义,将你的 Numeric_Expression 移到最后,其他表达式放在它前面:

Aggregate
   ( 
        ,[DISTRICTS D].[District]
        ,[WORK  D].[Work].[Work  Description]
        ,[Measures].[Actual Labour Hours]
   )

应该还是出错了。然后,您需要从前两个参数中创建一个元组集:

Aggregate
   ( 
        {(
         [DISTRICTS D].[District]
        ,[WORK  D].[Work].[Work  Description]
        )}
        ,[Measures].[Actual Labour Hours]
   )

您的错误消息现在应该消失了。