【问题标题】:MDX calculation. Divide each member by grand totalMDX 计算。将每个成员除以总计
【发布时间】:2015-09-08 10:39:04
【问题描述】:

样本数据

我已以以下格式导出 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。你有什么想法如何解决它吗?如果有什么不清楚的地方-问我,我会提供更多细节。

【问题讨论】:

  • 您的代码在我看来没问题。如果你用WITH member...代替create member,结果好吗?
  • 斯坦尼斯洛瓦斯 - 试试上面的 ^^
  • @SouravA 也许你误解了这个问题伙伴 - 我认为这个问题与“立方体脚本”有关......因此使用CREATE
  • @whytheq 没有​​。实际上,我想知道 Query Scoped 成员是否工作正常。我必须在 AW 中测试这个。

标签: sql-server ssas mdx olap cube-script


【解决方案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;

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

【讨论】:

  • 不会[Measures].[Net Weight])([Vendor Invoice].[Vendor Invoice No].CURRENTMEMBER, [Measures].[Net Weight]) 相同
  • 感谢您的回答,但SCOPE 有问题。当我尝试将 [Modified Percent] 添加到 excel 多维数据集时,它从 Running olap query 开始并冻结(等待 2 小时),如果我删除范围,它会正常添加,但百分比不正确。
  • 抱歉,是的,我原来的 SCOPE 语句中有一个递归。我现在已经更正了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多