MDX问题-将最高计数与排名/顺序功能一起使用

时间:2018-11-14 20:28:27

标签: mdx mdx-query

我该如何使用最高计数,以便它仅返回每个销售地区组(北美,太平洋等)销售量最高的前2条记录

WITH 
   MEMBER [Measures].[Group_Ranking_InternetSales] AS
   RANK( [Sales Territory].[Sales Territory Group].CurrentMember,
   ORDER( [Sales Territory].[Sales Territory Group].[Sales Territory Group].Members , [Measures].[Internet Sales Amount], BDESC)
   ) 

   MEMBER [Measures].[Group_Territory_Ranking_InternetSales] AS
   RANK(( [Sales Territory].[Sales Territory Group].CurrentMember,   [Sales Territory].[Sales Territory Country].CurrentMember),
   ORDER( CROSSJOIN([Sales Territory].[Sales Territory Group].CurrentMember,  [Sales Territory].[Sales Territory Country].[Sales Territory Country]) , [Measures].[Internet Sales Amount], BDESC)
   ) 
SELECT 
      {
   [Measures].[Group_Ranking_InternetSales]
   ,[Measures].[Group_Territory_Ranking_InternetSales] 
   , [Measures].[Internet Sales Amount]
      } ON COLUMNS,
   (
           ORDER  ([Sales Territory].[Sales Territory Group].[Sales Territory Group], [Measures].[Group_Ranking_InternetSales] , BASC ) 
   ,ORDER  ([Sales Territory].[Sales Territory Country].[Sales Territory Country], [Measures].[Group_Territory_Ranking_InternetSales] , BASC ) 
   )
   ON ROWS 
FROM
      [Adventure Works]

最终结果应该是它删除了下面突出显示的行。

enter image description here

1 个答案:

答案 0 :(得分:0)

立即尝试

                WITH 
            MEMBER [Measures].[Group_Ranking_InternetSales] AS
            RANK( [Sales Territory].[Sales Territory Group].CurrentMember,
            ORDER( [Sales Territory].[Sales Territory Group].[Sales Territory Group].Members , [Measures].[Internet Sales Amount], BDESC)
            ) 

            MEMBER [Measures].[Group_Territory_Ranking_InternetSales] AS
            RANK(( [Sales Territory].[Sales Territory Group].CurrentMember,   [Sales Territory].[Sales Territory Country].CurrentMember),
            ORDER( CROSSJOIN([Sales Territory].[Sales Territory Group].CurrentMember,  [Sales Territory].[Sales Territory Country].[Sales Territory Country]) , [Measures].[Internet Sales Amount], BDESC)
            ) 
            SELECT 
            {
            [Measures].[Group_Ranking_InternetSales]
            ,[Measures].[Group_Territory_Ranking_InternetSales] 
            , [Measures].[Internet Sales Amount]
            } ON COLUMNS,
            filter(///Added this
            (
            ORDER  ([Sales Territory].[Sales Territory Group].[Sales Territory Group], [Measures].[Group_Ranking_InternetSales] , BASC ) 
            ,ORDER  ([Sales Territory].[Sales Territory Country].[Sales Territory Country], [Measures].[Group_Territory_Ranking_InternetSales] , BASC ) 
            )
            ,[Measures].[Group_Territory_Ranking_InternetSales]<3) ///Added this
            ON ROWS 
            FROM
            [Adventure Works]