问题
Suppose that i have next MDX query
select
{
[Measures].[Measure1],
[Measures].[Measure2],
} on columns,
{
ORDER([Dim].Children, [Measures].[Measure1], desc)
} on rows
from [Cube]
which selects two measures and sorts rows by first one. How can sort by two measures, frist sort by Measure1 and then sort by Measure2?
回答1:
This works on AdvWrks for me:
SELECT
{
[Measures].[Reseller Order Quantity]
,[Measures].[Reseller Sales Amount]
} ON 0
,Order
(
Order
(
[Product].[Product].[Product].MEMBERS
,[Measures].[Reseller Sales Amount]
,BDESC
)
,[Measures].[Reseller Order Quantity]
,BDESC
) ON 1
FROM [Adventure Works];
Maybe you need to swap the order around and use BDESC:
SELECT
{
[Measures].[Measure1]
,[Measures].[Measure2]
} ON COLUMNS
,{
Order
(
Order
(
[Dim].Children
,[Measures].[Measure2]
,BDESC
)
,[Measures].[Measure1]
,BDESC
)
} ON ROWS
FROM [Cube];
回答2:
Try this:
select
{
[Measures].[Measure1],
[Measures].[Measure2]
} on columns,
{
ORDER(ORDER([Dim].Children, [Measures].[Measure1], desc), [Measures].[Measure2], DESC)
} on rows
from [Cube]
EDIT: Reason why it will not work is because the order of measures needed to be changed. Below is what I think happens:
Control first goes to inner set and it is ordered by the inner measure. This set returned is then sorted by the outer measure. The overall effect is that the outer measure supersedes the sorting by inner measure. So if we wanted to sort by m1->m2 then m1 needs to be the outer measure and m2, the inner measure.
来源:https://stackoverflow.com/questions/28689824/mdx-order-by-multiply-measures