Order

Sorts members of a set in order based on an expression.

Syntax

Order ( set, string_expr | numeric_value_expression [,BASC | BDESC] )
ParameterDescription

set

The set to sort.

string_expr

String sorting criteria.

numeric_value_expression

Numeric sorting criteria (see MDX Grammar Rules).

BASC

If this keyword is used, the returned set is arranged in ascending order. Ascending order is the default even if no keyword is used.

BDESC

If this keyword is used, the returned set is arranged in descending order.

Notes

This function ignores missing values.

Example

The following query displays budgeted Sales and Marketing in Qtr2, and the display of products is sorted based on ascending Actual Sales in Qtr1.

SELECT
 CrossJoin(
           {[Scenario].[Budget]}, 
           {[Measures].[Marketing], [Measures].[Sales]}
          )
ON COLUMNS,
 Order(
        [Product].Levels(0).Members,
        ([Year].[Qtr1], [Scenario].[Actual])
      ) 
ON ROWS
FROM Sample.Basic
WHERE ([Year].[Qtr2])

This query returns the grid:

(axis)BudgetBudget
(axis)MarketingSales
400-305103240
100-304503400
300-205503800
200-403102830
200-305504060
100-2011608800
100-2011608800
200-10209010330
400-208806590
300-10145010080
300-3010807880
300-3010807880
400-107907410
200-2010809590
200-2010809590
100-10180017230