首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将sql排名转换为mdx排名

将sql排名转换为mdx排名
EN

Stack Overflow用户
提问于 2019-11-03 15:02:49
回答 1查看 62关注 0票数 0

这是我的sql代码--我想把它转换成mdx查询。也可以将这些结果集用于power bi报告中。我无法将此sql查询写入mdx查询。有人能帮我吗?

代码语言:javascript
复制
    Select * From(
    Select 
    dense_RANK()over(partition by t.MonthName order by t.amount desc)rank
    ,t.*
    From( 
    Select DSP.SalesPointShortName ,dd.MonthName 
    ,SUM(fs.salesAmount)Amount
      From FactSales FS
    INNER JOIN DimDate dd on fs.DateKey=dd.DateKey
    INNER JOIN DimSalesPoint DSP on DSP.SalesPointID=FS.SalesPointID
    group by dsp.SalesPointShortName ,dd.MonthName 
    )as t  
    )as f where f.rank=1

我的预期输出是:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-03 18:51:29

很多谷歌搜索,我有从以下链接的答案后,这个链接期望的结果来了。https://bipassion.wordpress.com/2013/06/22/mdx-dense-rank/

`

代码语言:javascript
复制
 WITH SET [Sorted Models] AS
    // For each month get Top 25 records, choosed a Top 25 from business case
     Generate ( 
        [Dim Date].[Month Name].[Month Name].Members,
        TopCount 
          ( nonempty(
               {
                   [Dim Date].[Month Name].CurrentMember
                  * [Dim Sales Point].[SalesPoint].[Sales Point Short Name].MEMBERS              
                }
               ,[Measures].[Sales Amount] 
                 ) 
           , 1
           ,[Measures].[Sales Amount]
          )
          )
    //Select 
    //[Measures].[Sales Amount] on 0,[Sorted Models] on 1
   //From  [MdCubeTest]
   //where [Dim Product Group Item].[Sub Category Name].&[Bag]
    MEMBER [Measures].[Rank] AS
    // Get the Rank of current member Tuple to Current Month Set
    // Do not use Sorted Models set due to dynamic for each set
    Rank ( 
        (
        [Dim Date].[Month Name].CurrentMember 
        , [Dim Sales Point].[SalesPoint].CurrentMember    
        )
  ,  Generate ( [Dim Date].[Month Name].CurrentMember,
    TopCount 
      ( nonempty(
         { [Dim Date].[Month Name].CurrentMember
          * [Dim Sales Point].[SalesPoint].[Sales Point Short Name]          
                  }
           ,[Measures].[Sales Amount] 
           ) 
       , 25
       ,[Measures].[Sales Amount]
      )
     )
    , [Measures].[Sales Amount] 
    )

MEMBER [Measures].[Previous Set Index] AS
// Get the Set Index using Rank 
( 
[Measures].[Rank] - 2 
) 
MEMBER [Measures].[Dense Rank] AS
// Get the Dense Rank using the Index position value 
CASE
 WHEN [Measures].[Rank] = 1 
  THEN 1 
 ELSE
        ( 
        [Sorted Models].Item([Measures].[Previous Set Index]), 
        [Measures].[Dense Rank] 
        ) 
     + 
        Iif 
        ( 
             ( 
             [Sorted Models].Item([Measures].[Previous Set Index]), 
             [Measures].[Sales Amount] 
             ) 
          = 
             [Measures].[Sales Amount] 
         ,0 
         ,1 
        ) 
End

SELECT
  {
      [Measures].[Sales Amount]
    , [Measures].[Rank]
    , [Measures].[Dense Rank]
    //, [Measures].[Previous Set Index]
  } ON rows
 ,NON EMPTY
     {
     // FILTER Can be used to get the TOP 3 using DENSE RANK 
      FILTER (  
               [Sorted Models]
          , [Measures].[Dense Rank] <=1
          )

     } ON columns
    FROM  [MdCubeTest]
    where [Dim Product Group Item].[Sub Category Name].&[Bag]`
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58678087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档