衡量缺乏背景

时间:2014-11-14 13:03:11

标签: ssas mdx olap

我正在努力强制措施CountTopPromos具有背景性 目前,它正计算TopX所有元组的计数。对于我正在运行的AdWrks版本,这是14。

如何强制当前年度的上下文加入度量CountTopPromos

WITH 
  SET FullSet AS 
    NonEmpty
    (
        [Date].[Calendar].[Calendar Year].MEMBERS
      * 
        [Promotion].[Promotion].MEMBERS
     ,[Measures].[Reseller Order Count]
    ) 
  SET TopX AS 
    Generate
    (
      [Date].[Calendar].[Calendar Year].MEMBERS
     ,TopPercent
      (
          [Date].[Calendar].CurrentMember
        * 
          Extract
          (
            FullSet
           ,[Promotion].[Promotion]
          )
       ,90
       ,[Measures].[Reseller Order Count]
      )
    ) 
  MEMBER [Measures].[CountTopPromos] AS 
    Count(TopX)                  //<<<<<<<<<<<< CONTEXT LACKING HERE  <<<<<<<
SELECT 
  NON EMPTY 
    {[Measures].[CountTopPromos]} ON 0
 ,{TopX} ON 1
FROM [Adventure Works];

目前它返回以下内容:

enter image description here

我希望CountTopPromos在今年的背景下,所以期望的输出如下:

enter image description here

2 个答案:

答案 0 :(得分:1)

在定义轴之前评估集合(参见my answer to this question),如果使用命名集TopX,则无法在计算中获取行上下文。但是,您可以将其定义复制到[Measures].[CountTopPromos]的定义中,将[Date].[Calendar].[Calendar Year].MEMBERS替换为[Date].[Calendar].CurrentMember

  MEMBER [Measures].[CountTopPromos] AS 
    Count(    
        Generate
        (
          [Date].[Calendar].currentMember
         ,TopPercent
          (
              [Date].[Calendar].CurrentMember
            * 
              Extract
              (
                FullSet
               ,[Promotion].[Promotion]
              )
           ,90
           ,[Measures].[Reseller Order Count]
          )
        ) 
    ) 

提供您想要的结果。而且 - 由于Generate只会在这里只圈出一个成员 - 你也可以省略它:

  MEMBER [Measures].[CountTopPromos] AS 
    Count(    
         TopPercent
          (
              [Date].[Calendar].CurrentMember
            * 
              Extract
              (
                FullSet
               ,[Promotion].[Promotion]
              )
           ,90
           ,[Measures].[Reseller Order Count]
          )
        ) 

并会得到相同的结果。

答案 1 :(得分:0)

另一种非常漂亮的选择:

MEMBER [Measures].[CountTopPromos] AS 
  Count
  (
    Intersect
    (
      {
        [Date].[Calendar].CurrentMember * [Promotion].[Promotion].MEMBERS
      }
     ,TopX
    )
  )