0
votes

I can't write a MDX query for getting top 10 cities with hierarchy. There's an easy hierarchy of Countries and Cities.

My result should be:

+---------+------------+--------+
| Country |    City    | Amount |
+---------+------------+--------+
| USA     | New York   |    123 |
| Germany | Berlin     |     65 |
| USA     | California |     58 |
| Germany | Munich     |     48 |
| Spain   | Barcelona  |     47 |
| France  | Paris      |     42 |
| Britain | London     |     36 |
| Russia  | Moskow     |     30 |
| Czech   | Prague     |     18 |
| Spain   | Madrid     |     17 |
+---------+------------+--------+

But I get:

+---------+------------+--------+
| Country |    City    | Amount |
+---------+------------+--------+
| USA     | New York   |    123 |
| Germany | Berlin     |     65 |
| USA     | California |     58 |
| Germany | Munich     |     48 |
| Spain   | Barcelona  |     47 |
+---------+------------+--------+

MDX query:

WITH
SET [~ROWS] AS
    TopCount(Hierarchize({{[Site].[Country].Members}, {[Site].[City].Members}}), 10, [Measures].[Amount])
SELECT
NON EMPTY {[Measures].[Amount]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [My_Cube]

Of Course, I understand that Hierarchize({{[Site].[Country].Members}, {[Site].[City].Members}}) return set of tuples, but I don't know, What's the query should be?

1

1 Answers

0
votes

Try this, I used adventure works

select {[Measures].[Reseller Order Count]
} on columns,
topcount
(
([Geography].[Country].[Country],[Geography].[City].[City])
,10,[Measures].[Reseller Order Count]
)

on rows 
from [Adventure Works]

Result