基于 mdx 中数字的不同计数的数字平均值

Average of numbers based on distinct count of numbers in mdx

我有一个查询

select [num] on 0, [measure][count] on 1 from [table];

它给我说以下

[数量] -> 1 2 3
[计数] -> 3 4 5

现在我想取出以下的平均值,即 ( 1*3 + 2*4 + 3*5 )/(3+4+5)。

有人可以为它建议一个 mdx 查询吗?

下面的代码将每个成员的值乘以它的计数并将其加起来成为一个新的度量。

WITH MEMBER Measures.Multiplied AS

{num}.CURRENT.ITEM(0).ITEM(0).MEMBER_VALUE * [Measure].Count

MEMBER Measures.Avrg AS

SUM({num}, Measures.Multiplied)
/
SUM({num}, [Measure].Count)


select [num] on 0,
       {[measure].[count], Measures.Avrg} on 1
from [table];

更新

对于命名集,以下代码应该有效:

WITH set num as
{[Doc].[Time].[Time]}

MEMBER Measures.Avrg AS

SUM({num}, [Doc].[Time].CURRENTMEMBER.MEMBER_VALUE * [Measures].[Count])
/
SUM({num}, [Measures].[Count])


select [num] on 1,
       {[Measures].[Count], Measures.Avrg} on 0
from [Table];