简体   繁体   English

根据多维属性计算的SSAS成员

[英]Calculated SSAS Member based on multiple dimension attributes

I'm attempting to create a new Calculated Measure that is based on 2 different attributes. 我正在尝试创建一个基于2个不同属性的新计算度量。 I can query the data directly to see that the values are there, but when I create the Calculated Member, it always returns null. 我可以直接查询数据以查看值是否存在,但是当我创建计算成员时,它总是返回null。

Here is what I have so far: 这是我到目前为止的内容:

CREATE MEMBER CURRENTCUBE.[Measures].[Absorption]
 AS sum
(

    Filter([Expense].MEMBERS, [Expense].[Amount Category] = "OS"
           AND ([Expense].[Account Number] >= 51000 
           AND [Expense].[Account Number] < 52000))
    ,

    [Measures].[Amount - Expense]
), 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Expense';     

Ultimately, I need to repeat this same pattern many times. 最终,我需要多次重复相同的模式。 A particular accounting "type" (Absorption, Selling & Marketing, Adminstrative, R&D, etc.) is based on a combination of the Category and a range of Account Numbers. 特定的会计“类型”(吸收,销售和营销,管理,R&D等)基于类别和一系列帐号的组合。

I've tried several combinations of Sum, Aggregate, Filter, IIF, etc. with no luck, the value is always null. 我尝试了Sum,Aggregate,Filter,IIF等几种组合,但是没有运气,该值始终为null。

However, if I don't use Filter and just create a Tuple with 2 values, it does give me the data I'd expect, like this: 但是,如果我不使用Filter而是仅创建具有2个值的元组,它确实会为我提供期望的数据,如下所示:

CREATE MEMBER CURRENTCUBE.[Measures].[Absorption]
 AS sum
(

    {( [Expense].[Amount Category].&[OS], [Expense].[Account Number].&[51400]  )}
    ,

    [Measures].[Amount - Expense]
), 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Expense';  

But, I need to specify multiple account numbers, not just one. 但是,我需要指定多个帐号,而不仅仅是一个。

In general, you should only use the FILTER function when you need to filter your fact table based on the value of some measure (for instance, all Sales Orders where Sales Amount > 10.000). 通常,仅在需要根据某些度量值(例如,销售额> 10.000的所有销售订单)过滤事实表时,才应使用FILTER函数。 It is not intended to filter members based on dimension properties (although it could probably work, but the performance would likely suffer). 它并非旨在根据尺寸属性来过滤成员(尽管可能会起作用,但性能可能会受到影响)。

If you want to filter by members of one or more dimension attributes, use tuples and sets to express the filtering: 如果要按一个或多个维度属性的成员进行过滤,请使用元组和集合来表示过滤:

CREATE MEMBER CURRENTCUBE.[Measures].[Absorption]
AS 
    Sum( 
       {[Expense].[Account Number].&[51000]:[Expense].[Account Number].&[52000].lag(1)} *
       [Expense].[Amount Category].&[OS],
       [Measures].[Amount - Expense]
    ), 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Expense';

Here, I've used the range operator : to construct a set consisting of all [Account Number] members greater than or equal to 51000 and less than 52000. I then cross-join * this set with the relevant [Amount Category] attribute, to get the relevant set of members that I want to sum my measure over. 在这里,我使用的范围内操作:构建一套包含所有的[Account Number]至51000且小于52000。然后我交叉联接成员大于或等于*这一套有关[Amount Category]属性,以获得相关的成员集,我想总结一下自己的度量。

Note that this only works if you actually have a member with the account number 51000 and 52000 in your Expense dimension (see comments). 请注意,这仅在您的“支出”维度中确实有一个帐号为51000和52000的成员时有效(请参阅注释)。

An entirely different approach, would be to perform this logic in your ETL process. 完全不同的方法是在ETL过程中执行此逻辑。 For example you could have a table of account-number ranges that map to a particular accounting type (Absorption, Selling & Marketing, etc.). 例如,您可能有一个帐号范围表,该表映射到特定的会计类型(吸收,销售和营销等)。 You could then add a new attribute to your Expense-dimension, holding the accounting type for each account, and populate it using dynamic SQL and the aforementioned mapping table. 然后,您可以在费用维度中添加一个新属性,以保留每个帐户的会计类型,并使用动态SQL和上述映射表填充该属性。

I don't go near cube scripts but do you not need to create some context via the currentmember function and also return some values for correct evaluation against the inequality operators (eg > ) via the use of say the membervalue function ? 我不去接近立方体脚本,但你并不需要通过创造一些背景currentmember功能,也反对不平等的运营商(例如,对于正确评价返回一些值>通过使用说的) membervalue功能?

CREATE MEMBER CURRENTCUBE.[Measures].[Absorption]
 AS sum
(
    [Expense].[Amount Category].&[OS]
    *
    Filter(
       [Expense].[Account Number].MEMBERS,
       [Expense].[Account Number].currentmember.membervalue >= 51000 
       AND 
       [Expense].[Account Number].currentmember.membervalue < 52000
    )
    ,

    [Measures].[Amount - Expense]
), 
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Expense';  

EDIT 编辑

Dan has used the range operator : . Dan使用范围运算符: Please make sure your hierarchy is ordered correctly and that the members you use with this operator actually exist. 请确保正确排序您的层次结构,并确保您实际使用此运算符使用的成员。 If they do not exist then they will be evaluated as null : 如果它们不存在,那么它们将被评估为null

Against the AdvWks cube: 针对AdvWks多维数据集:

SELECT 
  {} ON 0
 ,{
      [Date].[Calendar].[Month].&[2008]&[4]
    : 
      [Date].[Calendar].[Month].&[2009]&[2]
  } ON 1
FROM [Adventure Works];

Returns the following: 返回以下内容:

在此处输入图片说明

If the left hand member does not exist in the cube then it is evaluated as null and therefore open ended on that side: 如果多维数据集中不存在左手成员,则将其评估为null ,因此在该侧打开结束:

SELECT 
  {} ON 0
 ,{
      [Date].[Calendar].[Month].&[2008]&[4]
    : 
      [Date].[Calendar].[Month].&[1066]&[2] //<<year 1066 obviously not in our cube
  } ON 1
FROM [Adventure Works];

Returns: 返回:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM