2017-08-11 112 views
0

Dears:發行訂購MDX查詢結果

我有以下MDX查詢。

WITH 
    MEMBER [Measures].[Member Full Path] AS 
     [Revenuedim_Client].CurrentMember.UniqueName 
    MEMBER [Measures].[Member Ordinal] AS 
     [Revenuedim_Client].CurrentMember.Ordinal 

    SELECT 
    NON EMPTY 
    Hierarchize(
    Union(
      Crossjoin([Measures].[BeaconAmount_USD] ,  
      LastPeriods(12,[Date.YQM].lastChild.lastChild.lastChild) 
      ) 
     , 
     Crossjoin({[Measures].[Member Ordinal], [Measures].[Member Full Path]},[Date.YQM].[2018]) 
    ) 
    ,POST) ON COLUMNS, 
     TOGGLEDRILLSTATE(
      TOGGLEDRILLSTATE(
       TOGGLEDRILLSTATE(
        TOGGLEDRILLSTATE(
         {[Revenuedim_Client].[All Clients] } , 
         {[Revenuedim_Client].[All Clients] } 
        ) 
       , {[Revenuedim_Client].[Group Client - Altria Group Inc.] } 
       ), {} 
      ), {} 
     ) ON ROWS from [Revenue_Client] 

這給我的輸出如下:

在行:客戶端(有4個級別向下鑽取最多項目級別) 在列:12個月+在電池滿員路徑 列:收入

查詢可以如何或在哪裏添加ORDER語句,以便根據12個月的總收入和大多數收入太少的收入對行進行排序,對於Revenuedim_client中的每個4個級別層次?

+0

訂單定義在這裏:https://docs.microsoft.com/en-us/sql/mdx/order-mdx ...你是否嘗試過應用它? – whytheq

+0

事實上,它是如此簡單:\t'ORDER( \t \t \t TOGGLEDRILLSTATE( \t \t \t \t TOGGLEDRILLSTATE( \t \t \t \t \t TOGGLEDRILLSTATE( \t \t \t \t \t \t TOGGLEDRILLSTATE( \t \t \t \t \t {[Revenuedim_Client]。[全部C lients]}, \t \t {$ {param_level1_m}} \t \t) \t \t,{$ {param_level2_m}} \t),{$ {param_level3_m}} \t),{$ {param_level4_m}} ) ,[措施]。 $ {MarketOrBeacon}, DESC)' – user1186098

回答

0

我認爲爲了讓事情變得更清楚一些,將12月設置爲WITH子句 - 然後添加一個成員聚合它 - 然後使用由這個新成員組成的元組以及收入作爲ORDER函數的數字參數。

WITH 
    MEMBER [Measures].[Member Full Path] AS 
    [Revenuedim_Client].CurrentMember.UniqueName 
    MEMBER [Measures].[Member Ordinal] AS 
    [Revenuedim_Client].CurrentMember.Ordinal 
    SET [12mth] AS 
    LastPeriods 
    (12 
    ,[Date.YQM].LastChild.LastChild.LastChild 
    ) 
    MEMBER [Date.YQM].[All].[12mth_Agg] AS 
    Aggregate([12mth]) 
SELECT 
    NON EMPTY 
    Hierarchize 
    (
     Union 
     (
     CrossJoin 
     (
      [Measures].[BeaconAmount_USD] 
     ,[12mth] 
     ) 
     ,CrossJoin 
     (
      { 
      [Measures].[Member Ordinal] 
      ,[Measures].[Member Full Path] 
      } 
     ,[Date.YQM].[2018] 
     ) 
    ) 
    ,POST 
    ) ON COLUMNS 
,Order 
    (
    ToggleDrillState 
    (
     ToggleDrillState 
     (
     ToggleDrillState 
     (
      ToggleDrillState 
      (
      {[Revenuedim_Client].[All Clients]} 
      ,{[Revenuedim_Client].[All Clients]} 
     ) 
     ,{[Revenuedim_Client].[Group Client - Altria Group Inc.]} 
     ) 
     ,{} 
    ) 
    ,{} 
    ) 
    ,[Date.YQM].[All].[12mth_Agg] //<<think I prefer to explicitly add what I'm ordering by 
    ,DESC 
) ON ROWS 
FROM [Revenue_Client];