将sql等级写入mdx等级

问题描述 投票:0回答:1

这是我的sql代码,我想将其转换为mdx查询。将这些结果集用于Power Bi报告中。我无法将这些sql查询写入mdx qyery。有谁能够帮助我。`

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

`我预期的结果是

Expected Output

ssas mdx
1个回答
0
投票

很多Google搜索,我从下面的链接中得到了答案遵循此链接愿望结果之后。https://bipassion.wordpress.com/tag/dax/

`

 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]`
© www.soinside.com 2019 - 2024. All rights reserved.