简体   繁体   English

按维筛选度量值会导致与计算所得成员中的IgnoreUnrelatedDimensions = True相似的行为

[英]Filtering measure by dimension causes similar behaviour to IgnoreUnrelatedDimensions = True in calculated member

I'm trying to define a calculated member in SSRS using SSAS that is the sum of a measure filtered on a value of a dimension. 我正在尝试使用SSAS在SSRS中定义一个计算成员,该成员是根据维值过滤的度量之和。 This works fine, except when I view the calculated member in the browser by the dimension I filtered on. 效果很好,除非我按过滤的维度在浏览器中查看计算所得的成员。 Instead of seeing null values where I would expect them, the grand total is repeated over the rows, similar to what happens when you set IgnoreUnrelatedDimensions to True on a measure group. 不会在期望的位置看到null值,而是在行上重复总计,类似于在度量值组IgnoreUnrelatedDimensions设置为True时发生的情况。

How can I fix this? 我怎样才能解决这个问题?

Example calculated member defined on the calculations tab in SSRS: 在SSRS的“计算”选项卡上定义的示例计算成员:

AGGREGATE({[Cow].[Hoof Location].[Front]}, [Measures].[Count])

This works fine when viewed against anything other than [Cow].[Hoof Location] . [Cow].[Hoof Location]以外的任何地方观看时,此效果都很好。 But when viewed by this dimension, Count is repeated across rows. 但是,从该维度查看时,Count将在各行之间重复。

You can try 你可以试试

IIf([Cow].[Hoof Location].CurrentMember IS [Cow].[Hoof Location].[All],
    AGGREGATE({[Cow].[Hoof Location].[Front]}, [Measures].[Count]),
    NULL
   )

Possibly you have to adapt the name of the All member to the name it has in your cube. 可能您必须使“ All成员的名称适应其在多维数据集中的名称。

Here is an MDX calculated measure that uses trick that you want: 这是使用所需技巧的MDX计算量度:

I used my base, so please substitute [Create Date].[Create Date].[Year].&[2014] with your own set and [Create Date].[Create Date].[Month] with your level of dimension [Cow] . 我用我的基地,所以请替换[Create Date].[Create Date].[Year].&[2014]用自己的一套和[Create Date].[Create Date].[Month]与你的尺寸的水平[Cow] Here is a standard 'Year-Month-Day' dimension. 这是标准的“年月日”维度。

CREATE MEMBER CURRENTCUBE.[Measures].[TestAgg]
 AS
    IIF(
        Intersect(
            [Create Date].[Create Date].CurrentMember
            ,Exists(
                Descendants(
                    [Create Date].[Create Date].[Year].&[2014]
                    ,[Create Date].[Create Date].[Month]
                    ,SELF_BEFORE_AFTER
                )
            )
        ).Count > 0
        ,[Measures].[Count]
        ,IIF(
            [Create Date].[Create Date].CurrentMember is [Create Date].[Create Date].[All]
            ,AGGREGATE(
                {[Create Date].[Create Date].[Year].&[2014]}
                ,[Measures].[Count])
            ,null
        )
    ),
VISIBLE = 1;

Here is some explanation: 这里是一些解释:

  1. I used Descendants to organize the set of necessary members. 我使用Descendants来组织必要的成员集。
  2. Intersect is used to understand whether the current member of the dimension is under this filter condition. Intersect用于了解尺寸的当前成员是否在此过滤条件下。
  3. Then the first IIF is used to show blanks in other years. 然后,第一个IIF用于显示其他年份的空白。
  4. The last IIF is used for the total. 最后一个IIF用于总计。

And some pictures of this measure's behavior: 以及有关该度量行为的一些图片:

天

月数

年份

If you want the same value on each level of 2014 and its children (but blanks for others), use 如果您希望在2014年的每个级别及其子级上使用相同的值(对于其他级别则为空白),请

AGGREGATE(
    {Exists(
        Descendants(
            [Create Date].[Create Date].[Year].&[2014],
            [Create Date].[Create Date].[Month],
            AFTER)
        )
    },
    [Measures].[Count]
)

or SUM . SUM But I guess it will look like IgnoreUnrelatedDimensions=True for this member and children, as you said before. 但是我想这个成员和孩子看起来像IgnoreUnrelatedDimensions=True ,就像您之前所说的那样。

One more tip: if there is a filtering on another levels you can play with Descendants levels and flag parameter ( AFTER , BEFORE , SELF_AND_AFTER etc.) This article can help to understand this technique: http://www.sqllion.com/2011/08/mdx-descendants/ 另一个提示:如果对其他级别进行过滤,则可以使用Descendants级别和标志参数( AFTERBEFORESELF_AND_AFTER等)进行SELF_AND_AFTER 。本文可以帮助您理解此技术: http : SELF_AND_AFTER / 08 / mdx-descendants /

Hope this will help to solve the problem. 希望这将有助于解决问题。

UPDATE For the lowest level it's better to use Ascendants like this: 更新对于最低级别,最好像这样使用Ascendants

CREATE MEMBER CURRENTCUBE.[Measures].[TestAgg2]
 AS
    IIF(
    Intersect(
        [Create Date].[Create Date].CurrentMember,
        Exists(
            Ascendants([Create Date].[Create Date].[Day].&[20140214])
        )
    ).Count > 0,
    (
        [Create Date].[Create Date].[Day].&[20140214],
        [Measures].[Count]
    ),
    IIF(
        [Create Date].[Create Date].CurrentMember is [Create Date].[Create Date].[All],
        AGGREGATE(
            {[Create Date].[Create Date].[Day].&[20140214]},
            [Measures].[Count]
        ),
        null
    )
),
VISIBLE = 1;

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

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