質問

I can't find out a way, how to sort my query, this is the simple query:

SELECT {[Measures].[IB]}
       ON COLUMNS,
       {[Dim_Product_Models_new].[PLA].members }  *   
       {[Dim Dates_new].[Date Full].&[2013-02-01]:[Dim Dates_new].[Date Full].&[2014-01-01]}
       ON ROWS
  FROM [cub_dashboard_spares]

The think is, I would get a result for 6 PLAs combined across 12 months (72 rows in total), however it is sorted alphabetically upon PLA.

What i need, is to sort the PLAs based on a measure in last month (2014-01-01 in this case).

Is there any way to perform this task so that the groupping (PLAs, Dates from 2013-02 to 2013-12) is perserved, but only the order of my PLAs is different. (PLA with highest measure in last month would be first, and so on)

Thank you very much for any kind of help

役に立ちましたか?

解決

Just put the sorted set on the rows, using the Order function. The third parameter of this function is DESC if you want to sort within each hierarchy level, but still want to get parents before children (like ALL before the single attribute members), or BDESC if you want to sort across all levels.

SELECT {[Measures].[IB]}
       ON COLUMNS,
       Order({[Dim_Product_Models_new].[PLA].members },
            ([Measures].[IB], [Dim Dates_new].[Date Full].&[2014-01-01]),
            DESC)
       *   
       {[Dim Dates_new].[Date Full].&[2013-02-01]:[Dim Dates_new].[Date Full].&[2014-01-01]}
       ON ROWS
  FROM [cub_dashboard_spares]

他のヒント

The order function over a crossjoin should preserve the initial order of the first set so reversing the order of the tuple will do the job:

 SELECT 
  { 
    [Measures].[IB] 
  } ON COLUMNS, 
  order( 
{[Dim Dates_new].[Date Full].&[2013-02-01]:[Dim Dates_new].[Date Full].&[2014-01-01]} * 
{[Dim_Product_Models_new].[PLA].members } , 
[Measures].[IB], 
desc 
) ON ROWS 
FROM [cub_dashboard_spares]

If you want to preserve the oder of appearance of the column labels, you can use the generate function like in the following example from the AW cube:

SELECT 
  {[Measures].[Internet Sales Amount]} ON 0
 ,Generate
  (
    {[Customer].[Country].&[Australia]:[Customer].[Country].&[United Kingdom]}
   ,(
      Order
      (
        [Date].[Calendar Year].[Calendar Year].MEMBERS
       ,(
          [Customer].[Country].CurrentMember
         ,[Measures].[Internet Sales Amount]
        )
       ,DESC
      )
     ,[Customer].[Country].CurrentMember
    )
  ) ON 1
FROM [Adventure Works];

Philip,

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top