MDX Aggregate() 对单个参数有何作用?

What does MDX Aggregate() do with a single argument?

我了解如何使用 MDX Aggregate() 和 Sum() 函数,以及它们之间的区别。

(一个有趣的是,在该级别的子级的层次结构中更高级别定义的度量的总和将该度量乘以子级的数量 - 而聚合 "correctly" returns 只是在更高级别定义的值)。

MSDN 上记录的语法是:

Aggregate(Set_Expression [ ,Numeric_Expression ])

我总是将它与两个参数一起使用。但是,当仅提供 set_expression 参数时,Aggregate 会做什么?文档(再次来自 MSDN)非常晦涩:

If a numeric expression is not provided, this function aggregates each measure within the current query context by using the default aggregation operator that is specified for each measure.

我在这样的 MDX 查询中尝试过:

WITH MEMBER WeekSummedTotal AS
Aggregate([Days].[WeeksAndDays].CurrentMember.Children)
SELECT 
{Measures.ThingoCount,Measures.WeekTotal,Measures.WeekSummedTotal} ON 0,
[Days].[WeeksAndDays].[WeekName] ON 1
FROM DateGRoupingTest

这有什么用? Aggregate 会在集合上聚合多维数据集的默认度量吗?还是集合Measures.Members?还是0轴上指定的那组其他措施?

None 个!查询运行并得到 returns 结果,但计算的度量 WeekSumTotal 显示#Error,并带有一个完全没有意义的错误:

Aggregate functions cannot be used on calculated members in the measures dimension

现在这是真的,但完全不相关。 None 计算了查询中的其他度量,实际上多维数据集没有任何计算成员。那么 Aggregate() 实际上试图在这里做什么?此错误消息(同样,在 MDX 中!)是否完全具有误导性?

添加: @whytheq 在下面的回答中建议使用聚合创建计算度量,但在备用维度层次结构而不是度量维度中创建它。这有效,但前提是包含与所选 "any old..." 维度的 [All] 成员的交叉连接。 在那里创建度量也使得不可能将两个(基本)度量和计算的度量放在同一个轴上。如果我尝试这样做:

{Measures.ThingoCount,Measures.WeekTotal,[Ages].[Age Key].WeekSummedTotal} ON 0,

我收到非常无用的错误消息:

Members, tuples or sets must use the same hierarchies in the  function.

我认为可以翻译成 "I can't make a set using the , (UNION) function between members of Measures and members of [Ages].[Age Key] because they're members of different dimensions"。

我的结论是,由于您的信息丰富的回答,只有一个参数的 Aggregate() 是一个棘手的野兽;我想知道为什么它的第二个参数是可选的?

我还注意到,尝试在我的年龄维度(只有一个层次结构,只有一个属性)上创建我的计算成员会给我误导性错误消息:

The 'Ages' dimension contains more than one hierarchy, therefore
the hierarchy must be explicitly specified.

除非我明确指定层次结构。 MDX 有很大的潜力,但如果 MS 投入更多精力使其正确反馈错误,学习曲线会更平缓。

采用 MSDN 定义的这一部分:

...this function aggregates each measure within the current query context ...

每个 脚本上下文中的度量如下:

{Measures.ThingoCount,Measures.WeekTotal,Measures.WeekSummedTotal}

现在 Measures.WeekSummedTotal 是度量维度中的计算成员 - 因此出现错误。

我想像下面这样的东西可以正常运行,您可以在其中使用 AggregateMeasures 以外的维度中创建成员?:

WITH 
  MEMBER [SomeSpareDim].[SomeSpareHier].WeekSummedTotal AS 
    Aggregate
    (
      [Days].[WeeksAndDays].CurrentMember.Children * [SomeDim].[SomeHier].[All]
    ) 
SELECT 
  [SomeSpareDim].[SomeSpareHier].WeekSummedTotal ON 0
 ,[Days].[WeeksAndDays].[WeekName] ON 1
FROM DateGRoupingTest;

可以更改以上内容以显示聚合非常有用:

WITH 
  MEMBER [Days].[WeeksAndDays].[Last3Weeks] AS 
    Aggregate
    (
      {
       [Days].[WeeksAndDays].[Weekx]
      ,[Days].[WeeksAndDays].[Weeky]
      ,[Days].[WeeksAndDays].[Weekz]
      }
    ) 
SELECT 
  {Measures.ThingoCount,Measures.WeekTotal} ON 0
 ,{
     //<< the following custom aggregated member will work for any measure, that is ON 0, via Aggregate
     //it can be mixed up with the normal members of the same hierarchy like the following
    [Days].[WeeksAndDays].[Last3Weeks]  
   ,[Days].[WeeksAndDays].[WeekName].members
  } ON 1
FROM DateGRoupingTest;

What would this do? Would Aggregate aggregate the cube's default measure over the set? Or the set Measures.Members? Or the set of other measures specified on the 0 axis?

Aggregate 函数聚合 当前 度量的集合 Measures 维度。如果度量在范围内,则为 "current"。如果度量不在范围内,则考虑 measures 维度的默认成员进行聚合。

可以通过多种方式将度量添加到范围,例如

在坐标轴上进行测量

with member [Customer].[Customer].abc as
aggregate([Customer].[Customer].members)


select [Customer].[Customer].abc on 0,
{[Measures].[Internet Sales Amount],[Measures].[Reseller Sales Amount]}  on 1
from [Adventure Works]

在上面的示例中,成员 abc 被计算了两次,每个度量一次。

使用子立方体

with member [Customer].[Customer].abc as
aggregate([Customer].[Customer].members)


select [Customer].[Customer].abc on 0
from (select {[Measures].[Internet Sales Amount] } on 0 from [Adventure Works])

有定义中的度量

with member [Customer].[Customer].abc as
aggregate([Customer].[Customer].members, [Measures].[Internet Sales Amount])


select [Customer].[Customer].abc on 0
from [Adventure Works]

Where子句中

with member [Customer].[Customer].abc as
aggregate([Customer].[Customer].members)


select [Customer].[Customer].abc on 0
from [Adventure Works]
where [Measures].[Internet Sales Amount]

正如 whytheq 所建议的那样,将成员置于其他维度层次结构组合中。否则,聚合函数可能会导致计算成员自引用自身。