订购一套复杂的套装

时间:2014-11-10 22:09:37

标签: ssas mdx olap

我一直在玩Chris Webb的剧本:http://cwebbbi.wordpress.com/2007/06/25/advanced-ranking-and-dynamically-generated-named-sets-in-mdx/

改编后的剧本如下:

WITH 
  SET MyMonths AS 
    TopPercent
    (
      [Date].[Calendar].[Month].MEMBERS
     ,20
     ,[Measures].[Reseller Sales Amount]
    ) 
  SET MyEmployees AS 
    [Employee].[Employee].[Employee].MEMBERS 
  SET MyMonthsWithEmployeesSets AS 
    Generate
    (
      MyMonths
     ,Union
      (
        {[Date].[Calendar].CurrentMember}
       ,StrToSet
        ("
         Intersect({}, 
         {TopCount(MyEmployees, 10, ([Measures].[Reseller Sales Amount],[Date].     [Calendar].CurrentMember))
         as EmployeeSet"
            + 
              Cstr(MyMonths.CurrentOrdinal)
          + "})"
        )
      )
    ) 
  MEMBER [Employee].[Employee].[RestOfEmployees] AS 
    Aggregate
    (
      Except
      (
        MyEmployees
       ,StrToSet
        (
          "EmployeeSet" + Cstr(Rank([Date].[Calendar].CurrentMember,MyMonths))
        )
      )
    ) 
  MEMBER [Measures].[EmployeeRank] AS 
    Rank
    (
      [Employee].[Employee].CurrentMember
     ,StrToSet
      (
        "EmployeeSet" + Cstr(Rank([Date].[Calendar].CurrentMember,MyMonths))
      )
    ) 
SELECT 
  {
    [Measures].[EmployeeRank]
   ,[Measures].[Reseller Sales Amount]
  } ON 0
 ,Hierarchize
  (
    Union
    (
      Filter
      (
        MyMonthsWithEmployeesSets * MyEmployees   //<<<HERE<<<<
       ,
        [Measures].[EmployeeRank] >= 1
      )
     ,{
        MyMonthsWithEmployeesSets * [Employee].[Employee].[RestOfEmployees]
      }
    )
  ) ON 1
FROM [Adventure Works];

我如何ORDER输出,以便每组10名员工按顺序1到10,MEMBER名为RestOfEmployees总是在第11位找到,即它应该遵循会员排名10?

诱惑是在标记为ORDER的点处添加HERE函数,即该行将变为:

MyMonthsWithEmployeesSets * ORDER(MyEmployees, [Measures].[EmployeeRank])

这样做会导致以下错误消息:

  

维度&#39; [EmployeeSet0]&#39;在解析字符串[EmployeeSet0]时,在多维数据集中找不到。

我相信这是因为度量EmployeeRank使用了在生成函数期间创建的内联集。

1 个答案:

答案 0 :(得分:1)

如果您为EmployeeRank重新定义RestOfEmployees为11,则只需将该成员添加到Filter的第一个参数集,然后应用Order ,因为它将在位置1到10之后排序:

WITH 
  SET MyMonths AS 
    TopPercent
    (
      [Date].[Calendar].[Month].MEMBERS
     ,20
     ,[Measures].[Reseller Sales Amount]
    ) 
  SET MyEmployees AS 
    [Employee].[Employee].[Employee].MEMBERS 
  SET MyMonthsWithEmployeesSets AS 
    Generate
    (
      MyMonths
     ,Union
      (
        {[Date].[Calendar].CurrentMember}
       ,StrToSet
        ("
         Intersect({}, 
         {TopCount(MyEmployees, 10, ([Measures].[Reseller Sales Amount],[Date].     [Calendar].CurrentMember))
         as EmployeeSet"
            + 
              Cstr(MyMonths.CurrentOrdinal)
          + "})"
        )
      )
    ) 
  MEMBER [Employee].[Employee].[RestOfEmployees] AS 
    Aggregate
    (
      Except
      (
        MyEmployees
       ,StrToSet
        (
          "EmployeeSet" + Cstr(Rank([Date].[Calendar].CurrentMember,MyMonths))
        )
      )
    ) 
  MEMBER [Measures].[EmployeeRank] AS 
    IIF([Employee].[Employee].CurrentMember IS [Employee].[Employee].[RestOfEmployees], 
        11,
        Rank
        (
          [Employee].[Employee].CurrentMember
         ,StrToSet
          (
            "EmployeeSet" + Cstr(Rank([Date].[Calendar].CurrentMember,MyMonths))
          )
        ) 
    )
SELECT 
  {
    [Measures].[EmployeeRank]
   ,[Measures].[Reseller Sales Amount]
  } ON 0
 ,
   Order(
      Filter
      (
        MyMonthsWithEmployeesSets  
          * UNION(MyEmployees, {[Employee].[Employee].[RestOfEmployees]})
       ,
        [Measures].[EmployeeRank] >= 1
      ), [Measures].[EmployeeRank]
      )
  ON 1
FROM [Adventure Works];