MDX 表示层次结构子集的总计百分比
我有一些基本的 mdx 问题。我需要计算层次结构中总数的百分比,当我想要一个不包含完整层次结构的结果集时,我遇到了问题。
我有一个相当基本的维度,看起来
Groups
Group A
Item 1
Item 2
Item 3
Group B
Item 4
Item 5
Group C
Item 6
Item 7
Item 8
我正在使用我在阅读中发现的计算度量,如果我查看完整的层次结构,它效果很好,但当我想查看子集时,它就会崩溃。
例如,
WITH MEMBER [Measures].[Percent] AS iif([Measures].[Result Count] = 0,
NULL,
IIF(isempty( ([Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1).Dimension.CurrentMember.Parent )),1,
[Measures].[Result Count] / ( [Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent ))), FORMAT_STRING ="#,##0.00 %;-#,##0.00 %"
SELECT
{ [Measures].[Result Count],[Measures].[Percent] } ON COLUMNS,
{ [Groups].[Group Participation]} ON ROWS
FROM [Cube]
我得到以下信息:
Result Count Percent
Group A 1541 11.92 %
Group B 2300 17.79 %
Group C 9086 70.29 %
效果很好。但是,如果我只想要 B 组和 B 组C 组:
WITH MEMBER [Measures].[Percent] AS iif([Measures].[Result Count] = 0,
NULL,
IIF(isempty( ([Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent )),1,
[Measures].[Result Count] / ( [Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent ))), FORMAT_STRING ="#,##0.00 %;-#,##0.00 %"
SELECT
{ [Measures].[Result Count],[Measures].[Percent] } ON COLUMNS,
{ [Groups].[Group Participation].&[1],[Groups].[Group Participation].&[2]} ON ROWS
FROM [Cube]
我得到以下信息:
Result Count Percent
Group B 2300 17.79 %
Group C 9086 70.29 %
我想要
Result Count Percent
Group B 2300 20.20 %
Group C 9086 79.79 %
基本上,我需要将百分比总和加起来为 100。
我还需要它在叶节点上工作。当我将语句更改为仅返回第 4 项、第 5 项、第 6 项时
WITH MEMBER [Measures].[Percent] AS iif([Measures].[Result Count] = 0,
NULL,
IIF(isempty( ([Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent )),1,
[Measures].[Result Count] / ( [Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent ))), FORMAT_STRING ="#,##0.00 %;-#,##0.00 %"
SELECT
{ [Measures].[Result Count],[Measures].[Percent] } ON COLUMNS,
{ [Groups].[Group].&[4],[Groups].[Group].&[5],[Groups].[Group].&[6]} ON ROWS
FROM [Cube]
,我得到以下信息:
Result Count Percent
Item 4 103 4.48 %
Item 5 12 0.52 %
Item 6 455 19.78 %
我想要
Result Count Percent
Item 4 103 18.07 %
Item 5 12 2.10 %
Item 6 455 79.82 %
我觉得我缺少一些非常基本的东西。我的计算方法做错了什么?
提前致谢。
i have some what of a basic mdx question. I need to caclulate the percent of total in a hierarchy and i'm having problems when i want a result set that doesn't include the complete hierarchy.
i have a fairly basic dimension that looks like
Groups
Group A
Item 1
Item 2
Item 3
Group B
Item 4
Item 5
Group C
Item 6
Item 7
Item 8
I'm using a calculated measure i found in my readings that works well if I'm looking at the complete hierarchy, but falls apart when i want to look at a subset.
For example,
WITH MEMBER [Measures].[Percent] AS iif([Measures].[Result Count] = 0,
NULL,
IIF(isempty( ([Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1).Dimension.CurrentMember.Parent )),1,
[Measures].[Result Count] / ( [Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent ))), FORMAT_STRING ="#,##0.00 %;-#,##0.00 %"
SELECT
{ [Measures].[Result Count],[Measures].[Percent] } ON COLUMNS,
{ [Groups].[Group Participation]} ON ROWS
FROM [Cube]
I get the following:
Result Count Percent
Group A 1541 11.92 %
Group B 2300 17.79 %
Group C 9086 70.29 %
Which works great. However, if i only want Group B & Group C:
WITH MEMBER [Measures].[Percent] AS iif([Measures].[Result Count] = 0,
NULL,
IIF(isempty( ([Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent )),1,
[Measures].[Result Count] / ( [Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent ))), FORMAT_STRING ="#,##0.00 %;-#,##0.00 %"
SELECT
{ [Measures].[Result Count],[Measures].[Percent] } ON COLUMNS,
{ [Groups].[Group Participation].&[1],[Groups].[Group Participation].&[2]} ON ROWS
FROM [Cube]
I get the following:
Result Count Percent
Group B 2300 17.79 %
Group C 9086 70.29 %
I want
Result Count Percent
Group B 2300 20.20 %
Group C 9086 79.79 %
Basically, i need the sum of the percent to add up to 100.
I also need this to work at the leaf nodes. when i change the statment to only return Item 4, Item 5, Item 6
WITH MEMBER [Measures].[Percent] AS iif([Measures].[Result Count] = 0,
NULL,
IIF(isempty( ([Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent )),1,
[Measures].[Result Count] / ( [Measures].[Result Count], Axis(1)(0)( Axis(1)(0).Count - 1 ).Dimension.CurrentMember.Parent ))), FORMAT_STRING ="#,##0.00 %;-#,##0.00 %"
SELECT
{ [Measures].[Result Count],[Measures].[Percent] } ON COLUMNS,
{ [Groups].[Group].&[4],[Groups].[Group].&[5],[Groups].[Group].&[6]} ON ROWS
FROM [Cube]
I get the following:
Result Count Percent
Item 4 103 4.48 %
Item 5 12 0.52 %
Item 6 455 19.78 %
I want to get
Result Count Percent
Item 4 103 18.07 %
Item 5 12 2.10 %
Item 6 455 79.82 %
I feel like i'm missing something very basic. What am i doing wrong in my calculated measure?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过在计算的百分比成员中指定过滤视图的维度成员(叶节点)解决了这个问题,而不是使用 axis() 。在我正在开发的 Web 应用程序中,MDX 是动态生成的,因此很容易实现。
在上面的示例中,这意味着对于叶节点(返回项 4,5 和 6 的示例),它应该如下所示:
而不是:
I solved this problem by specifying dimension members (leaf nodes) of the filtered view in the calculated percentage member, instead of using
axis()
. In the web app I'm working on, MDX is generated on the fly so it was easy to implement it.In the example above, this would mean that for leaf nodes (examples that returns items 4,5 and 6) it should look like this:
instead of:
您不应再使用维度(父级)的“自然”层次结构来获取总计,而应在计算成员中使用轴上的总和。
这应该会得到你的“视觉”百分比。
You should not use anymore the 'natural' hierarchy of a dimension (parent) to get the total but use a sum over the axis in your calculated members.
That should get your 'visual' percentage.