在 MDX 中计算百分比
calculating percentage in MDX
我正在尝试编写一个 mdx 查询来计算 3 个不同列中每个产品的收入百分比,具体取决于百分比 "base" - 组(产品所在)收入,子组收入和总收入。到目前为止这是我的代码
with
member [Measures].[Percent] as
([Measures].[Income]) /
([Products].[product].currentmember.parent,
[Measures].[Income])
,format_string = "percent"
select
{
[Measures].[Percent]
}
on columns,
{
[Products].[Product].[Product]
}
on rows
from [CUBE]
它根据总收入计算百分比,但我不知道如何更改代码来满足我之前提到的条件。我尝试以多种不同方式多次重新排列代码,(尝试计算 sobgroup 百分比示例)
with
member [Measures].[Percent] as
([Measures].[Income], [Products].[Subgroup]) /
([Products].[product].currentmember.parent,
[Measures].[Income])
,format_string = "percent"
etc 但我只得到相同的结果或错误。我对 mdx 还是很陌生,所以任何帮助或提示都将不胜感激。
我仍然有点不确定要求,但如果您愿意,可以添加额外的家长:
WITH
MEMBER [Measures].[Percent_ofSubCategory] as
DIVIDE(
[Measures].[Income]
,([Measures].[Income], [Towary].[Hierarchy].currentmember.parent)
)
,format_string = "percent"
MEMBER [Measures].[Percent_ofCategory] as
DIVIDE(
[Measures].[Income]
,([Measures].[Income], [Towary].[Hierarchy].currentmember.parent.parent)
)
,format_string = "percent"
MEMBER [Measures].[Percent_ofAll] as
DIVIDE(
[Measures].[Income]
,([Measures].[Income], [Towary].[Hierarchy].[All])
)
,format_string = "percent"
SELECT
{
[Measures].[Percent_ofSubCategory]
,[Measures].[Percent_ofCategory]
,[Measures].[Percent_ofAll]
}
on 0,
[Towary].[Hierarchy].[Towar].[Towar].members
on 1
from [CUBE];
我正在尝试编写一个 mdx 查询来计算 3 个不同列中每个产品的收入百分比,具体取决于百分比 "base" - 组(产品所在)收入,子组收入和总收入。到目前为止这是我的代码
with
member [Measures].[Percent] as
([Measures].[Income]) /
([Products].[product].currentmember.parent,
[Measures].[Income])
,format_string = "percent"
select
{
[Measures].[Percent]
}
on columns,
{
[Products].[Product].[Product]
}
on rows
from [CUBE]
它根据总收入计算百分比,但我不知道如何更改代码来满足我之前提到的条件。我尝试以多种不同方式多次重新排列代码,(尝试计算 sobgroup 百分比示例)
with
member [Measures].[Percent] as
([Measures].[Income], [Products].[Subgroup]) /
([Products].[product].currentmember.parent,
[Measures].[Income])
,format_string = "percent"
etc 但我只得到相同的结果或错误。我对 mdx 还是很陌生,所以任何帮助或提示都将不胜感激。
我仍然有点不确定要求,但如果您愿意,可以添加额外的家长:
WITH
MEMBER [Measures].[Percent_ofSubCategory] as
DIVIDE(
[Measures].[Income]
,([Measures].[Income], [Towary].[Hierarchy].currentmember.parent)
)
,format_string = "percent"
MEMBER [Measures].[Percent_ofCategory] as
DIVIDE(
[Measures].[Income]
,([Measures].[Income], [Towary].[Hierarchy].currentmember.parent.parent)
)
,format_string = "percent"
MEMBER [Measures].[Percent_ofAll] as
DIVIDE(
[Measures].[Income]
,([Measures].[Income], [Towary].[Hierarchy].[All])
)
,format_string = "percent"
SELECT
{
[Measures].[Percent_ofSubCategory]
,[Measures].[Percent_ofCategory]
,[Measures].[Percent_ofAll]
}
on 0,
[Towary].[Hierarchy].[Towar].[Towar].members
on 1
from [CUBE];