Ssas MDX Aggregate()对单个参数有什么作用?
我了解如何使用MDX Aggregate()和Sum()函数,以及它们之间的区别 (一个有趣的问题是,在层次结构中较高级别的子级上定义的度量值的总和乘以子级的数量,而聚合“正确”仅返回较高级别上定义的值) 上记录的语法是: 我总是在两个论点中使用它。但是当只提供set_expression参数时,Aggregate做什么呢?文档(同样来自MSDN)非常模糊: 如果未提供数值表达式,此函数将使用为每个度量值指定的默认聚合运算符聚合当前查询上下文中的每个度量值 我在MDX查询中进行了如下尝试:Ssas MDX Aggregate()对单个参数有什么作用?,ssas,mdx,Ssas,Mdx,我了解如何使用MDX Aggregate()和Sum()函数,以及它们之间的区别 (一个有趣的问题是,在层次结构中较高级别的子级上定义的度量值的总和乘以子级的数量,而聚合“正确”仅返回较高级别上定义的值) 上记录的语法是: 我总是在两个论点中使用它。但是当只提供set_expression参数时,Aggregate做什么呢?文档(同样来自MSDN)非常模糊: 如果未提供数值表达式,此函数将使用为每个度量值指定的默认聚合运算符聚合当前查询上下文中的每个度量值 我在MDX查询中进行了如下尝试: WI
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
这会怎么样?是否会在集合上聚合多维数据集的默认度量值?还是设定的尺度,成员们?或在0轴上指定的一组其他度量
这些都不是!查询将运行并返回结果,但calcd measure WeekSumTotal显示#Error,其中有一个完全没有意义的错误:
聚合函数不能用于度量维度中的计算成员
这是真的,但完全无关。查询中没有计算任何其他度量值,事实上,多维数据集没有任何计算成员。那么,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.
The 'Ages' dimension contains more than one hierarchy, therefore
the hierarchy must be explicitly specified.
我认为,这可以解释为“我不能使用度量值成员和[Ages].[Age Key]成员之间的(并集)函数来创建集合,因为它们是不同维度的成员”
我的结论是,多亏了你们提供的信息丰富的答案,只有一个参数的Aggregate()是一只狡猾的野兽;我想知道为什么它的设计带有第二个可选参数
我还注意到,试图在我的年龄维度(只有一个层次结构,只有一个属性)上创建我的计算成员会给我带来误导性的错误消息:
Members, tuples or sets must use the same hierarchies in the function.
The 'Ages' dimension contains more than one hierarchy, therefore
the hierarchy must be explicitly specified.
除非我明确指定层次结构。MDX有着巨大的潜力,但如果MS更加努力使其正确地反馈错误,学习曲线将变得更加平缓。参考MSDN定义的这一部分: …此函数聚合当前查询中的每个度量值 上下文 脚本上下文中的每个度量值如下所示:
{Measures.ThingoCount,Measures.WeekTotal,Measures.WeekSummedTotal}
现在,Measures.WeekSummedTotal
是度量维度中的计算成员,因此存在错误
我可以想象下面这样的功能正常,您可以使用Aggregate
在维度中创建一个成员,而不是Measures
?:
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;
与
成员[日][周和日][最近3周]为
总数的
(
{
[天][WeeksAndDays][Weekx]
,[Days].[WeeksAndDays].[Weeky]
,[Days].[WeeksAndDays].[Weekz]
}
)
挑选
0上的{Measures.ThingoCount,Measures.WeekTotal}
,{
//
这会做什么?会聚合多维数据集的默认值吗
度量集合?或集合度量。成员?或其他集合
在0轴上指定的度量值
Aggregate
函数为Measures
维度聚合当前度量值上的集合。如果度量值在范围内,则度量值为“当前”。如果度量值不在范围内,则聚合将考虑来自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)
select [Customer].[Customer].abc on 0
from [Adventure Works]
where [Measures].[Internet Sales Amount]
具有定义中的度量值
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 (select {[Measures].[Internet Sales Amount] } on 0 from [Adventure Works])
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所建议的,将成员放在其他维度层次结构组合上。否则,聚合函数可能会导致计算成员自引用自身。@GregGalloway-一个给你!我认为计算度量值试图引用自身是对的。你的代码运行时没有错误,并且计算ed member聚合度量值。DefaultMember度量值。在我对问题的编辑中有更多反馈。元问题:我可以将你的答案和@SouravA的答案都标记为答案吗?它们都是非常有用的答案。@SebTHU,随你怎么想。我很高兴知道你的度量值是引用自身的。我可能看到了这个例外在之前,我没有逻辑地思考为什么-谢谢你的问题。非常透彻地解释了“当前查询上下文中的每个度量值”实际上意味着什么!为什么他们不付钱给你来编写MSDN文档?;)谢谢,受宠若惊。我希望在未来几十年内写一篇。为什么你不能把它作为Sum([Days])来写呢。[WeeksAndDays].CurrentMember.Children[Measures].Somememeasure)
?问题解决了。当然,这更容易,而且确实给了我想要的结果(尽管就我而言,聚合比求和更好)。我只是想更好地理解MDX:我想知道“无二次参数”是什么意思Sum/Aggregate的使用确实进行了实验,结果令人困惑。但我认为你和@whytheq已经解释了发生的事情。