如何正确计算测量值以进行汇总?
我创建了一个计算指标,用于计算属于各种风险评级的所有贷款的当前余额的加权比率:
WITH
MEMBER [MEASURES].[Weighted Ratio] AS
(Measures.[Current Balance] * [Risk Rating].[Loan Rating Code].CurrentMember.member_value) /
(
[Measures].[Current Balance],
Ancestor([Risk Rating].[Loan Rating Code].CurrentMember, 1)
), FORMAT_STRING = "Standard"
SELECT
{[Measures].[Current Balance], [Measures].[Weighted Ratio]} on COLUMNS,
[Risk Rating].[Loan Rating Code].MEMBERS ON ROWS
FROM
[Test Cube]
问题是结果仅在儿童级别返回,而不是求和:
Current Balance Weighted Ratio
All $3,245,749,329.46 (null)
0 $661,388.20 0.00
1 $17,341,801.10 0.01
2 $117,188,374.06 0.07
3 $596,477,812.37 0.55
4 $1,266,047,841.51 1.56
5 $986,789,425.72 1.52
6 $119,055,732.16 0.22
7 $133,050,242.69 0.29
8 $9,136,711.65 0.02
我怎样才能得到sum 显示在所有级别而不是 (null)?
I have created a calculated measure that computes a weighted ratio for the current balance of all loans that fall into various risk ratings:
WITH
MEMBER [MEASURES].[Weighted Ratio] AS
(Measures.[Current Balance] * [Risk Rating].[Loan Rating Code].CurrentMember.member_value) /
(
[Measures].[Current Balance],
Ancestor([Risk Rating].[Loan Rating Code].CurrentMember, 1)
), FORMAT_STRING = "Standard"
SELECT
{[Measures].[Current Balance], [Measures].[Weighted Ratio]} on COLUMNS,
[Risk Rating].[Loan Rating Code].MEMBERS ON ROWS
FROM
[Test Cube]
The problem is that the results come back only at the child level, instead of being summed up:
Current Balance Weighted Ratio
All $3,245,749,329.46 (null)
0 $661,388.20 0.00
1 $17,341,801.10 0.01
2 $117,188,374.06 0.07
3 $596,477,812.37 0.55
4 $1,266,047,841.51 1.56
5 $986,789,425.72 1.52
6 $119,055,732.16 0.22
7 $133,050,242.69 0.29
8 $9,136,711.65 0.02
How can I get the sum to show up at the All level instead of (null)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您在编写
上面的函数“当涉及到根(所有级别)时尝试找到其祖先”时没有考虑根成员,这可能就是您在该级别得到 null 的原因。您应该决定当涉及
[风险评级].[贷款评级代码]
维度的成员“所有级别”时该怎么做。看起来,当涉及到根级别时,您只需要返回一个常量值“1”即可。如果是这样,您应该更改您的查询,如下所示;
如果您想在根级别返回另一个结果,只需更改
Then
部分的逻辑即可。It looks like you didn't consider root member when you writing
When it comes to Root (All Level) above function try to find its ancestor and that's probably why you get null at that level. You should decide what to do when it comes to member "All Level" of
[Risk Rating].[Loan Rating Code]
dimension.It looks like you just need to return a constant value "1" when it comes to the root level. If it is so, you should change your query as below;
If you want to return another result when it comes to root level just change the logic at the
Then
section.我能够在我的计算度量中使用 IsLeaf() 和递归来使其工作:
现在结果看起来像我想要的:
I was able to get this to work using IsLeaf() and recursion in my calculated measure:
Now the results look like I wanted: