如何在此查询中的不同值的总和中添加过滤器(每周)

时间:2016-05-12 13:17:06

标签: sql-server ssas mdx

我在互联网上找到了以下示例,它为不同的[Measures].[Job Advert Value]计算了总和[JAP ID].[JAP ID]

然而,它只显示了所有内容的总和,我想仅为每周总结一次。

我尝试为时间维度[Time].[Year - Week - Date].[Week].members添加FILTER,但不起作用。

以下查询无需FILTER功能。

SCOPE([Time].[Year - Week - Date].[Week].members, [Permanent Placement Value].[Value Type Name].&[Vacancies], [Measures].[Job Advert Value] );

    [Measures].[JAP Advert Value] = 
 SUM 
    (
            generate
            (
                [JAP ID].[JAP ID].MEMBERS AS s,
                s.CURRENT *
                TAIL(
                    NonEmpty
                        (
                         [Time].[Year - Week - Date].[Date].members, 
                         (s.CURRENT, [Measures].[Job Advert Value])
                        )
                    )
            )
        , 
        Measures.[Job Advert Value]
    );

END SCOPE; 

1 个答案:

答案 0 :(得分:0)

我建议您尝试以下方法之一:

SCOPE([Time].[Year - Week - Date].[Week].members
    , [Permanent Placement Value].[Value Type Name].&[Vacancies]
    , [Measures].[Job Advert Value] );

[Measures].[JAP Advert Value] = 
SUM(
  GENERATE(
    [JAP ID].[JAP ID].MEMBERS AS s
   ,s.CURRENT *
    TAIL(
     NONEMPTY(
       EXISTING [Time].[Year - Week - Date].[Date].MEMBERS
       ,(
         s.CURRENT
        ,[Measures].[Job Advert Value]
        )
      )
    )
  )
,Measures.[Job Advert Value]
);

END SCOPE;

SCOPE([Time].[Year - Week - Date].[Week].members
    , [Permanent Placement Value].[Value Type Name].&[Vacancies]
    , [Measures].[Job Advert Value] );

[Measures].[JAP Advert Value] = 
SUM(
  GENERATE(
    [JAP ID].[JAP ID].MEMBERS AS s
   ,s.CURRENT *
    TAIL(
      NONEMPTY(
       [Time].[Year - Week - Date].CURRENTMEMBER
       ,(
         s.CURRENT
        ,[Measures].[Job Advert Value]
        )
      )
    )
  )
,Measures.[Job Advert Value]
);

END SCOPE;

另外,我建议您尝试使用以下内容进行示范:

SCOPE([Permanent Placement Value].[Value Type Name].&[Vacancies]
, [Measures].[Job Advert Value] );