2016-05-13 65 views
0

我试图编写一个mdx查询来计算3个不同列中每个产品的收入百分比,具体取决于百分比“基数” - 集团(即产品所在)收入,小组收入和总收入。到目前为止,这是我的代码在MDX中计算百分比

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] 

它calulates基于总收入的百分比,但我不知道如何更改代码,以填补我在前面提到的标准。我试图rearrenging代码多次在许多不同的方式,(试图计算sobgroup个例子)

with 
member [Measures].[Percent] as 
([Measures].[Income], [Products].[Subgroup])/
([Products].[product].currentmember.parent, 
[Measures].[Income]) 
,format_string = "percent" 

等,但我只得到了相同的结果或错误。我仍然对mdx很陌生,所以任何帮助或提示将不胜感激。

+0

你有一个产品 - 分组层次到位? – SouravA

+0

层次结构是Group - Subgroup - Product – some

+0

ok,但会有一个用户层次结构,其中包含层级,并且用户层次结构中的每个层级都会有单独的属性层次结构。你能添加一个链接到层次结构的图片吗? – whytheq

回答

0

我仍然要求有点不确定,但你可以,如果你想添加一个额外的父:

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]; 
+0

** [图片](http://www48.zippyshare.com/i/PxGUER4d/9174863/percent.png)**是查询结果。层次结构是Group - Subgroup - Product。 – some

+0

我修改了我的脚本,但我认为您使用的是属性层次结构 - 多维数据集中是否存在多级用户层次结构? – whytheq

+0

非常感谢您的时间,但脚本结果仍然是一样的。我不确定它是否回答您的问题,但立方体有2种度量方式(实际数据和计划的结果)和4个维度(时间,客户,区域和产品),每个维度除客户和地区之外都有其层次结构。这里有一个** [图片](http://www110.zippyshare.com/i/9ZZSaudh/1429523/hierarchy.png)**产品层次 – some