与儿童和父母一起计算MDX(对总数的贡献)

时间:2015-10-28 18:30:06

标签: mdx olap iccube

我得到了一个多维数据集,其中包含一些城市街区的地籍信息。其中一项措施是“地籍价值”:邻里土地的价值。 现在,城市被划分为区域和区域,进入社区(层级有两个层次)。

问题是:我需要计算每个社区的价值与父母(地区)和总数(城市)相比的百分比,以及与城市相比的地区相同的百分比。

我该怎么做?

我试过了:

WITH MEMBER
[Measures].[Percentage] AS 
  ([Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember
   /[Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember.Parent)

SELECT 
 {[Measures].[Percentage]} ON 0,
 [Nbh].[Nbh].[Nbh].AllMembers ON 1
FROM Cadastre

尺寸为:

Nbh:邻居

Cad值:地籍值

我得到的是每个结果值中的“错误”,解释是“当前成员():参数(0)类型不匹配:预期:'级别|层次结构|维度',得到:'度量'”

我做错了什么?

3 个答案:

答案 0 :(得分:1)

尝试以下方法:

WITH MEMBER [Measures].[Parent %] AS 
   IIF(
    [Nbh].[Nbh].CURRENTMEMBER IS [Nbh].[Nbh].[All]
    ,1
    ,[Measures].[Cad value] /
     (
      [Measures].[Cad value],
      [Nbh].[Nbh].CurrentMember.Parent
     )
   ), FORMAT_STRING = 'Percent'
SELECT 
 {[Measures].[Parent %]} ON 0,
 [Nbh].[Nbh].[Nbh].AllMembers ON 1
FROM Cadastre;

包括IIF是一种防御措施。如果您切换到显示完整层次结构的AllMembers,则会包含All成员。以下是使用AdvWrks

的示例
WITH 
  MEMBER [Measures].[Parent %] AS 
    IIF
    (
        [Product].[Subcategory].CurrentMember
      IS 
        [Product].[Subcategory].[All Products]
     ,1
     ,
        [Measures].[Internet Sales Amount]
      / 
        (
          [Measures].[Internet Sales Amount]
         ,[Product].[Subcategory].CurrentMember.Parent
        )
    ) 
   ,FORMAT_STRING = 'Percent' 
SELECT 
  NON EMPTY 
    {[Measures].[Parent %]} ON 0
 ,NON EMPTY 
    [Product].[Subcategory].ALLMEMBERS ON 1
FROM [Adventure Works];

以上内容将返回以下内容:

enter image description here

如果没有IIF,则表达式如下:

WITH 
  MEMBER [Measures].[Parent %] AS 
      [Measures].[Internet Sales Amount]
    / 
      (
        [Measures].[Internet Sales Amount]
       ,[Product].[Subcategory].CurrentMember.Parent
      ) 
   ,FORMAT_STRING = 'Percent' 
SELECT 
  NON EMPTY 
    {[Measures].[Parent %]} ON 0
 ,NON EMPTY 
    [Product].[Subcategory].ALLMEMBERS ON 1
FROM [Adventure Works];

由于缺乏远见,我们得到以下信息:

enter image description here

答案 1 :(得分:0)

  

WITH MEMBER [Measures]。[Percentage] AS
  ([Nbh]。[Nbh]。[Nbh],[Measures]。[Cad value] .CurrentMember        /[Nbh].[Nbh].[Nbh],[Measures].[Cad value] .CurrentMember.Parent)

这有两个问题:

一,您使用静态集来计算计算成员的值,即: [Nbh].[Nbh].[Nbh] 这不是[Nbh].[Nbh].CURRENTMEMBER

第二个和更大的错误:在度量上使用currentmember。你不能这样做。您可以使用Measures.CURRENTMEMBER,但就是这样。它最适用于轴上使用的层次结构。

那就是说,你的方法几乎是合法的。您需要获取父级的度量值。

这应该有效:

WITH MEMBER
[Measures].[Percentage] AS 
DIVIDE
        (
        [Measures].[Cad value], 
        ([Nbh].[Nbh].CURRENTMEMBER.PARENT,[Measures].[Cad value]) //Cad value for parent
        )

SELECT 
 {[Measures].[Percentage]} ON 0,
 [Nbh].[Nbh].[Nbh].AllMembers ON 1
FROM Cadastre

答案 2 :(得分:-1)

错误肯定是因为这个陈述不正确:

WITH MEMBER
[Measures].[Percentage]
AS ([Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember/[Nbh].[Nbh].[Nbh],[Measures].[Cad value].CurrentMember.Parent)

尝试像这样做

WITH MEMBER
[Measures].[Percentage]
AS ([Nbh].[Nbh].[Nbh],[Measures].[Cad value])/([Nbh].[Nbh].[Nbh],[Measures].[Cad value])