Вершина X вершины Y с членом RestOf, где X и Y - иерархии из разных измерений

Это прекрасно работает:

WITH 
  SET [AllCountries] AS [Country].[Country].MEMBERS 
  SET [AllStates]    AS [State-Province].[State-Province].MEMBERS 
  SET [Top2States] AS 
    Generate
    (
      [AllCountries]
     ,TopCount
      (
        (EXISTING 
          [AllStates])
       ,3
       ,[Measures].[Internet Order Count]
      )
    ) 
  MEMBER [State-Province].[All].[RestOfCountry] AS 
    Aggregate({(EXISTING {[AllStates]} - [Top2States])}) 
SELECT 
  {[Measures].[Internet Order Count]} ON COLUMNS
 ,{
      [AllCountries]
    * 
      {
        [State-Province].[All]
       ,[Top2States]
       ,[State-Province].[All].[RestOfCountry]
      }
  } ON ROWS
FROM [Adventure Works];

EXISTING Ключевое слово очень помогает.

Если две иерархииON ROWS не из того же измерения, как страны и государства в вышеприведенном, то у нас есть что-то вроде следующего:

WITH 
  SET [AllCountries] AS [Country].[Country].MEMBERS 
  SET [AllCats]      AS [Product].[Category].[Category].MEMBERS 
  SET [Top5Cats] AS 
    Generate
    (
      [AllCountries]
     ,TopCount
      (
        (EXISTING 
          [AllCats])
       ,5
       ,[Measures].[Internet Order Count]
      )
    ) 
  MEMBER [Product].[Category].[All].[RestOfProds] AS 
    Aggregate({(EXISTING {[AllCats]} - [Top5Cats])}) 
SELECT 
  {[Measures].[Internet Order Count]} ON COLUMNS
 ,{
      [AllCountries]
    * 
      {
        [Product].[Category].[All]
       ,[Top5Cats]
       ,[Product].[Category].[All].[RestOfCountry]

      }
  } ON ROWS
FROM [Adventure Works];

Вы можете видеть в результатах вышеупомянутого, что один и тот же набор категорий повторяется для каждой страны, в том же порядке, то есть механизм не находит topCount для каждой страны.EXISTING сейчас избыточно.

Как мы можем адаптировать второй скрипт выше так, чтобы он имел функции, аналогичные верхнему скрипту?

редактировать

Лучший пример - использование Product. Это как если бы двигатель находилTopCount для всех стран, а затем положить один и тот же набор против каждой страны. Я хотел быTopCount для каждой страны:

WITH 
  SET [AllCountries] AS 
    [Country].[Country].MEMBERS 
  SET [AllProds] AS 
    [Product].[Product].[Product].MEMBERS 
  SET [Top5Prods] AS 
    Generate
    (
      [AllCountries]
     ,TopCount
      (
        (EXISTING 
          [AllProds])
       ,5
       ,[Measures].[Internet Order Count]
      )
    ) 
  MEMBER [Product].[Product].[All].[RestOfProds] AS 
    Aggregate({(EXISTING {[AllProds]} - [Top5Prods])}) 
SELECT 
  {[Measures].[Internet Order Count]} ON COLUMNS
 ,NON EMPTY 
    {
        [AllCountries]
      * 
        {
          [Product].[Product].[All]
         ,[Top5Prods]
         ,[Product].[Product].[All].[RestOfProds]
        }
    } ON ROWS
FROM [Adventure Works];

Edit2

Это последняя версия с помощью идей Сурава - к сожалению, члены RestOfProds не работают должным образом:

WITH 
  SET [AllCountries] AS 
    [Country].[Country].MEMBERS 
  SET [AllProds] AS 
    [Product].[Product].[Product].MEMBERS 
  SET [Top5Prods] AS 
    Generate
    (
      [AllCountries] AS a
     ,
        {
            (
              a.Current
             ,[Product].[Product].[All]
            )
          + 
            //The top x prods
            TopCount
            (
              NonEmpty
              (
                a.Current * [AllProds]
               ,[Measures].[Internet Sales Amount]
              )
             ,5
             ,[Measures].[Internet Sales Amount]
            )
        }
    ) 
  SET [RestOfProds] AS 
    Extract
    (
      {[AllCountries] * [AllProds]} - [Top5Prods]
     ,[Product].[Product]
    ) 
  MEMBER [Product].[Product].[All].[RestOfProds] AS 
    Aggregate([RestOfProds]) 
SELECT 
  {[Measures].[Internet Sales Amount]} ON COLUMNS
 ,{
    [Top5Prods]
   ,
    [AllCountries] * [Product].[Product].[All].[RestOfProds]
  } ON ROWS
FROM [Adventure Works];

Edit3

Следующее имеет правильный порядок, так что членRestOfProds всегда следует за соответствующей топ-5

WITH 
  SET [AllCountries] AS 
    [Country].[Country].MEMBERS 
  SET [AllProds] AS 
    [Product].[Product].[Product].MEMBERS 
  SET [Top5Prods] AS 
    Generate
    (
      [AllCountries] AS a
     ,{
        //The top x prods
        TopCount
        (
          NonEmpty
          (
            a.Current * [AllProds]
           ,[Measures].[Internet Sales Amount]
          )
         ,5
         ,[Measures].[Internet Sales Amount]
        )
      }
    ) 
  MEMBER [Product].[Product].[All].[RestOfProds] AS 
    Aggregate([Country].CurrentMember * [AllProds] - [Top5Prods]) 
SELECT 
  {[Measures].[Internet Sales Amount]} ON COLUMNS
 ,Generate
  (
    [AllCountries] AS X
   ,
      Order
      (
        Intersect
        (
          X.CurrentMember * [AllProds]
         ,[Top5Prods]
        )
       ,[Measures].[Internet Sales Amount]
       ,bdesc
      )
    + 
      {X.CurrentMember * {[Product].[Product].[All].[RestOfProds]}}
  ) ON ROWS
FROM [Adventure Works];

Edit4

Следующее имеет правильный порядок, так что членRestOfProds всегда следует за соответствующей верхней 5 + Я добавил еще один набор в строках:

WITH 
  SET [2months] AS 
    {
      [Date].[Calendar].[Month].&[2007]&[9]
     ,[Date].[Calendar].[Month].&[2007]&[10]
    } 
  SET [AllCountries] AS 
    [Country].[Country].MEMBERS 
  SET [MthsCountries] AS 
    [2months] * [AllCountries] 
  SET [AllProds] AS 
    [Product].[Product].[Product].MEMBERS 
  SET [Top5Prods] AS 
    Generate
    (
      [MthsCountries] AS A
     ,{
        //The top x prods
        TopCount
        (
          NonEmpty
          (
            A.Current * [AllProds]
           ,[Measures].[Internet Sales Amount]
          )
         ,5
         ,[Measures].[Internet Sales Amount]
        )
      }
    ) 
  MEMBER [Product].[Product].[All].[RestOfProds] AS 
    Aggregate
    (
        ([Date].[Calendar].CurrentMember,[Country].CurrentMember) * [AllProds]
      - 
        [Top5Prods]
    ) 
SELECT 
  {[Measures].[Internet Sales Amount]} ON COLUMNS
 ,Generate
  (
    [MthsCountries] AS X
   ,
      Order
      (
        Intersect
        (
          X.Current * [AllProds]
         ,[Top5Prods]
        )
       ,[Measures].[Internet Sales Amount]
       ,bdesc
      )
    + 
      {X.Current * {[Product].[Product].[All].[RestOfProds]}}
  ) ON ROWS
FROM [Adventure Works];

Ответы на вопрос(3)

Ваш ответ на вопрос