1

我得到了一个包含城市某些街区的地籍信息的立方体。其中一项措施是“地籍价值”:一个社区的土地价值。现在,城市分为区和区,分为街区(等级分为两级)。

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

我该怎么做?

我试过了:

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)类型不匹配:预期:'level|hierarchy|dimension',得到:'measure'”

我究竟做错了什么?

4

3 回答 3

1

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

这有两个问题:

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

第二个也是更大的错误:使用currentmemberon 度量。你不能那样做。你可以使用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
于 2015-10-29T07:40:52.533 回答
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];

以上返回以下内容:

在此处输入图像描述

没有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];

由于缺乏远见,我们得到以下结果:

在此处输入图像描述

于 2015-10-28T21:53:40.637 回答
-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])
于 2015-10-28T21:33:20.363 回答