MDX 计算。将每个成员除以总计

MDX calculation. Divide each member by grand total

示例数据

我以下列格式导出了 OLAP 多维数据集(测量 [Some Percent] 用法是 Average over time):

             [Net Weight]   [Some Percent]
             4 387          2,10%
             3 304          1,60%
Grand total: 7 691          1,85% -- Percent is AVG

公式

我需要创建新的计算成员 [Modified Percent],应该按以下方式计算:

[Net Weight].[1] / [Net Weight].[Total] * [Some Percent].[1] + 
[Net Weight].[2] / [Net Weight].[Total] * [Some Percent].[2] +
[Net Weight].[n] / [Net Weight].[Total] * [Some Percent].[n] -- can be n rows

带有示例数据的公式

所以我的示例数据将是:

4 387 / 7691 * 2,10 +   |   1,20%
3 304 / 7691 * 1,60     |   0,69%
                    =   |   1,89% -- Sum of percent 

期望输出

[Modified Percent] 应按以下方式返回:

             [Net Weight]   [Some Percent]             [Modified Percent]
             4 387          2,10%                      1,20%
             3 304          1,60%                      0,69%
Grand total: 7 691          1,85% -- Percent is AVG    1,89%

MDX 脚本

现在我在下面有 MDX Script,但是 [Modified Percent] 返回与 [Some Percent]

相同的值
CREATE MEMBER CURRENTCUBE.[Measures].[Modified Percent]
 AS ([Measures].[Net Weight] / sum([Vendor Invoice].[Vendor Invoice No].[All],[Measures].[Net Weight]))  * [Measures].[Some Percent], 
FORMAT_STRING = 'Percent', 
NON_EMPTY_BEHAVIOR = { [Net Weight] }, 
VISIBLE = 1;   

也试过这个,可惜,也是同样的结果:

CREATE MEMBER CURRENTCUBE.[Measures].[Modified Percent]
 AS ([Vendor Invoice].[Vendor Invoice No].CurrentMember,[Measures].[Net Weight]) / 
     iif(
        ([Vendor Invoice].[Vendor Invoice No].CurrentMember.Parent,[Measures].[Net Weight]) = 0,
        ([Vendor Invoice].[Vendor Invoice No].CurrentMember,[Measures].[Net Weight]),
        ([Vendor Invoice].[Vendor Invoice No].CurrentMember.Parent,[Measures].[Net Weight])
        )
      * [Measures].[Some Percent], 
FORMAT_STRING = 'Percent', 
NON_EMPTY_BEHAVIOR = { [Net Weight] }, 
VISIBLE = 1; 

貌似分割部分返回 1.你有什么解决办法吗?如果有什么不清楚 - 问我,我会提供更多细节。

问题是计算是在总(全部)级别上应用的,其中 [Measures].[Net Weight] 等于 SUM([Vendor Invoice].[Vendor Invoice No].[All], [Measures].[Net Weight]),因此调整因子为 1.0

尝试将整个块放在立方体的 MDX 计算脚本中:

CREATE MEMBER CURRENTCUBE.[Measures].[Modified Percent]
     AS ([Measures].[Net Weight]
         / sum([Vendor Invoice].[Vendor Invoice No].[All], [Measures].[Net Weight]))
       * [Measures].[Some Percent], 
    FORMAT_STRING = 'Percent', 
    NON_EMPTY_BEHAVIOR = { [Net Weight] }, 
    VISIBLE = 1;  

SCOPE ([Measures].[Modified Percent], [Vendor Invoice].[Vendor Invoice No].[All]);
    this = SUM([Vendor Invoice].[Vendor Invoice No].[All].children, [Measures].[Modified Percent]));
END SCOPE;

这会覆盖总数并告诉它对子项求和,而不是重新计算。