MDX SSAS Rank rownumber函数

时间:2017-04-17 19:53:48

标签: ssas mdx rank partition

我有一个现有的SSRS报告来自T-SQL查询,我试图在SSAS多维数据集上使用MDX查询重新创建它。我很难重写行数和排名逻辑到MDX。

写成:

SELECT ceil((ROW_NUMBER() OVER (PARTITION BY PRODUCT ORDER BY YEARMONTH))/12)

SQL中的Rank1。有人可以告诉我,如果可以使用MDX完成吗?在立方体中,PRODUCT和YEARMONTH来自不同的维度。

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

有Rank()函数。例如:

with
Dynamic Set OrderedSet as
Order(
    NonEmptyCrossJoin(
       [Date].[Year].[Year].Members,
       [Product].[Product].[Product].Members,
       [Measures].[Invoice Count],
       2
    ),
    [Measures].[Invoice Count],
    BDESC
)

Member [Measures].[Rank] as
Rank(
        ([Client].[Client].Currentmember,[Date].[Year].CurrentMember),
        OrderedSet
)

select {[Measures].[Invoice Count],[Measures].[Rank]} on 0,
non empty OrderedSet on 1
from [BI Fake]
where ([Date].[Day].&[20160120])

您可以从我的blog post了解详情。

答案 1 :(得分:0)

您可以使用Generate重复这样的排名:

WITH 
  SET [SalesRank] AS 
    Generate
    (
      [Customer].[Customer Geography].[State-Province]
     ,Order
      (
        NonEmpty
        (
          (
            [Customer].[Customer Geography].CurrentMember
           ,[Product].[Product Categories].[Subcategory]
          )
         ,{[Measures].[Internet Sales Amount]}
        )
       ,[Measures].[Internet Sales Amount]
       ,BDESC
      )
    ) 
  MEMBER [Measures].[CategoryRank] AS 
    Rank
    (
      (
        [Customer].[Customer Geography].CurrentMember
       ,[Product].[Product Categories].CurrentMember
      )
     ,Exists
      (
        [SalesRank]
       ,[Product].[Product Categories].CurrentMember
      )
    ) 
SELECT 
  {
    [Measures].[Internet Sales Amount]
   ,[Measures].[CategoryRank]
  } ON 0
 ,[SalesRank] ON 1
FROM [Adventure Works];

结果如下:

enter image description here