This works fine:
WITH
SET [AllCountries] AS [Country].[Country].MEMBERS
SET [AllStates] AS [State-Province].[State-Province].MEMBERS
SET [Top2Sta
This seems to work ok:
WITH
SET [AllCountries] AS
[Country].[Country].MEMBERS
SET [AllProds] AS
[Product].[Product].[Product].MEMBERS
SET [Top5Prods] AS
Generate
(
[AllCountries] AS a
,{
(
a.CurrentMember
,[Product].[Product].[All]
)
+
//The top x prods
a.CurrentMember
*
TopCount
(
[AllProds]
,5
,[Measures].[Internet Sales Amount]
)
}
)
MEMBER [Product].[Product].[All].[Other Products] AS
Aggregate
(
[Country].CurrentMember * [Product].[Product].[Product].MEMBERS
-
[Top5Prods]
)
SELECT
{[Measures].[Internet Sales Amount]} ON COLUMNS
,Hierarchize(
{
[Top5Prods]
,[AllCountries] * [Product].[Product].[All].[Other Products]
}
) ON ROWS
FROM [Adventure Works];
EXISTING
when used on named sets, doesn't really make a difference since named sets are created before the axes members are laid out. In your case, GENERATE
is really just creating static sets and then on the axes everything is just cross joined.
To get the TopCount
script working, you need to handle all the cross joins
inside one set so that everything is evaluated together. I am not sure, but you might try the below:
WITH
SET [AllCountries] AS [Country].[Country].MEMBERS
SET [AllCats] AS [Product].[Category].[Category].MEMBERS
SET [Top5Cats] AS
Generate
(
[AllCountries] as a
,
{
(a.current , [Product].[Category].[All] ) //The ALL member
+
TopCount //The top 2 categories
(
NonEmpty((a.current * [AllCats] ) , (a.CURRENT, [Measures].[Internet Order Count]))
,2
,[Measures].[Internet Order Count]
)
}
+
{ //The rest of the members
a.current * [AllCats]
-
a.current *{
TopCount
(
NonEmpty([AllCats] , (a.CURRENT, [Measures].[Internet Order Count]))
,2
,[Measures].[Internet Order Count]
)
}
}
)
MEMBER [Product].[Category].[All].[RestOfProds] AS
Aggregate({(EXISTING {[AllCats]} - [Top5Cats])})
SELECT
{[Measures].[Internet Order Count]} ON COLUMNS,
[Top5Cats] ON ROWS
FROM [Adventure Works];
EDIT:
If you need the RestOfCats
member, you can add this code.
SET [RestOfCats] AS
EXTRACT
(
{
[AllCountries] * [AllCats]
-
[Top5Cats]
},
[Product].[Category]
)
MEMBER [Product].[Category].[All].[RestOfCats] AS
Aggregate([RestOfCats])
EDIT 2
Continuing on your example, removing the 'All' member additionally in the definition.
SET [RestOfProds] AS
Extract
(
{[AllCountries] * [AllProds]} - [Top5Prods] - [AllCountries]*[Product].[Product].[All]
,[Product].[Product]
)
If you are crossjoining multiple hierarchies in the same dimension only valid combinations will be shown. This is called auto-exists and it explains why the first query works like you want.
When crossjoining hierarchies from different dimensions the auto-exists does not happen. I think this explains the odd combinations returned in the second query.
Try adding NON EMPTY at the beginning of your ON ROWS definition. Then it will only return combinations which have an Internet Order Count measure value (whatever measures are on columns). That's the proper way to limit the crossjoin.
If you don't want a NON EMPTY on Internet Order Count then so you need a NonEmpty(, [Measures].[A Different Measure]) on a different measure?
Edit: It looks like the issue is not related to auto-exists but is related to performing a different TopCount per country. So this info may help someone else but isn't the answer to this question.