Ardalan Shahgholi
Ardalan Shahgholi

Reputation: 12555

Sort In MDX Query not work

I use SSAS and SQL Server 2008R2

I use AdventureWorkDW dimensional Database.

I write this query :

Select
[Measures].[Internet Sales Amount] on columns,
order(
        [Product].[Product Categories].[Subcategory],
        [Measures].[Internet Sales Amount],
        asc
    ) on rows
From [Adventure Works]

I got result like this :

enter image description here

also i write this query :

Select
[Measures].[Internet Sales Amount] on columns,
non empty order(
                crossjoin(
                    [Product].[Category].[Category],
                    [Product].[Subcategory].[Subcategory]
                     ),
                [Measures].[Internet Sales Amount],
                desc
                ) on rows
From [Adventure Works]

And result is not sorted also :

enter image description here

Why result was not sorted?

Upvotes: 0

Views: 214

Answers (1)

Justin
Justin

Reputation: 9724

Query (2012sql):

Select
[Measures].[Internet Sales Amount] on columns,
order(
        [Product].[Product Categories].[Subcategory],
        [Measures].[Internet Sales Amount],
        basc
    ) on rows
From [Adventure Works]

The problem was I think because data was hierarchical and with basc you sort just with Amount.

The Order function can either be hierarchical (as specified by using the ASC or DESC flag) or nonhierarchical (as specified by using the BASC or BDESC flag

Result (2012sql):

|                GG | INTERNET SALES AMOUNT |
|-------------------|-----------------------|
|            Lights |                (null) |
|             Locks |                (null) |
|          Panniers |                (null) |
|             Pumps |                (null) |
|        Bib-Shorts |                (null) |
|            Tights |                (null) |
|   Bottom Brackets |                (null) |
|            Brakes |                (null) |
|            Chains |                (null) |
|         Cranksets |                (null) |
|       Derailleurs |                (null) |
|             Forks |                (null) |
|        Handlebars |                (null) |
|          Headsets |                (null) |
|   Mountain Frames |                (null) |
|            Pedals |                (null) |
|       Road Frames |                (null) |
|           Saddles |                (null) |
|    Touring Frames |                (null) |
|            Wheels |                (null) |
|             Socks |             $5,106.32 |
|          Cleaners |             $7,218.60 |
|              Caps |            $19,688.10 |
|            Gloves |            $35,020.70 |
|             Vests |            $35,687.00 |
|        Bike Racks |            $39,360.00 |
|       Bike Stands |            $39,591.00 |
|   Hydration Packs |            $40,307.67 |
|           Fenders |            $46,619.58 |
| Bottles and Cages |            $56,798.19 |
|            Shorts |            $71,319.81 |
|           Jerseys |           $172,950.68 |
|           Helmets |           $225,335.60 |
|   Tires and Tubes |           $245,529.32 |
|     Touring Bikes |         $3,844,801.05 |
|    Mountain Bikes |         $9,952,759.56 |
|        Road Bikes |        $14,520,584.04 |

Upvotes: 1

Related Questions