2015-07-10 79 views
1

我無法弄清楚我將如何做一個簡單的「order by」子句。您將如何訂購MDX查詢

以下是我的查詢 - 我將如何訂購Service Name,然後通過Adjusted Incidents

SELECT 
    {[Measures].[Adjusted Incidents]} ON COLUMNS 
,NON EMPTY 
    { 
     [Completed Inspections].[Service Name].[Service Name].ALLMEMBERS 
     * 
     [Inspected Items].[Item Name].[Item Name].ALLMEMBERS 
    } 
    DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS 
FROM 
(
    SELECT 
    { 
     [Completed Inspections].[Customer Id].&[DRHOD] 
    ,[Completed Inspections].[Customer Id].&[EMHST] 
    ,[Completed Inspections].[Customer Id].&[EXHOU] 
    ,[Completed Inspections].[Customer Id].&[ETRAD] 
    } ON COLUMNS 
    FROM [Inspections] 
) 
WHERE 
    (
    [Calendar].[Month].&[2015-05-01T00:00:00] 
    ,[Completed Inspections].[Is Reinspection].&[False] 
) 
CELL PROPERTIES VALUE; 
+0

也許這是一個副本:http://stackoverflow.com/questions/28689824/mdx-order-by-multiply-measures – whytheq

回答

1

沒有訂單在mdx類似sql的條款。

您需要將函數ORDER應用於您要訂購的任何套件。這裏是msdn定義:
https://msdn.microsoft.com/en-us/library/ms145587.aspx

嵌套訂單不mdx那麼微不足道 - 訂單的內部程序,是你想要的順序首先應用外窩你想第二個應用順序:

SELECT 
    {[Measures].[Adjusted Incidents]} ON COLUMNS 
,NON EMPTY 
    Order 
    (
     Order 
     (
     { 
      [Completed Inspections].[Service Name].[Service Name].ALLMEMBERS 
      * 
      [Inspected Items].[Item Name].[Item Name].ALLMEMBERS 
     } 
     ,[Measures].[Adjusted Incidents] 
     ,BDESC //<<you have 4 choices here BDESC, BASC, DESC, or ASC 
    ) 
    ,[Completed Inspections].[Service Name].CurrentMember.Member_Caption 
    ,BDESC //<<you have 4 choices here BDESC, BASC, DESC, or ASC 
    ) 
    DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS 
FROM 
(
    SELECT 
    { 
     [Completed Inspections].[Customer Id].&[DRHOD] 
    ,[Completed Inspections].[Customer Id].&[EMHST] 
    ,[Completed Inspections].[Customer Id].&[EXHOU] 
    ,[Completed Inspections].[Customer Id].&[ETRAD] 
    } ON COLUMNS 
    FROM [Inspections] 
) 
WHERE 
    (
    [Calendar].[Month].&[2015-05-01T00:00:00] 
    ,[Completed Inspections].[Is Reinspection].&[False] 
) 
CELL PROPERTIES VALUE; 
+0

謝謝你,這工作完美!讓我頭疼! –

+0

沒問題 - 當我第一次玩它時,嵌套順序的順序導致了我嚴重的頭部劃傷 – whytheq