MDX - TOP N PARENT WITH TOP N CHILDS

WITH 
  SET [CountryRankSet] AS 
    Order
    (
      NonEmpty
      (
        [Geography].[Country].[Country].MEMBERS
       ,[Measures].[Internet Sales Amount]
      )
     ,[Measures].[Internet Sales Amount]
     ,desc
    ) 
      MEMBER [Measures].[CountryRank] AS 
    Rank
    (
      [Geography].[Country].CurrentMember
     ,CountryRankSet
    ) 
  
  SET [ProductRankSet] AS 
    Order
    (
      NonEmpty
      (
        [Product].[Product].[Product].MEMBERS
       ,[Measures].[Internet Sales Amount]
      )
     ,[Measures].[Internet Sales Amount]
     ,desc
    ) 
      MEMBER [Measures].[ProductRank] AS 
    Rank
    (
      [Product].[Product].CurrentMember
     ,ProductRankSet
    ) 
SELECT 
  {[Measures].[CountryRank],[Measures].[ProductRank],[Measures].[Internet Sales Amount]} ON 0
 
 ,Generate
  (
    [Geography].[Country].[Country].MEMBERS
   ,TopCount
    (
      Order
      (
          [Geography].[Country].CurrentMember
        * 
          [Product].[Product].[Product].MEMBERS
       ,[Measures].[Internet Sales Amount]
       ,DESC
      )
     ,3
    )
  ) ON 1
FROM [Adventure Works];

CountryRankProductRankInternet Sales Amount
AustraliaRoad-150 Red, 4811$1,205,876.99
AustraliaRoad-150 Red, 6212$1,202,298.72
AustraliaRoad-150 Red, 5213$1,080,637.54
CanadaRoad-150 Red, 4821$1,205,876.99
CanadaRoad-150 Red, 6222$1,202,298.72
CanadaRoad-150 Red, 5223$1,080,637.54
FranceRoad-150 Red, 4831$1,205,876.99
FranceRoad-150 Red, 6232$1,202,298.72
FranceRoad-150 Red, 5233$1,080,637.54
GermanyRoad-150 Red, 4841$1,205,876.99
GermanyRoad-150 Red, 6242$1,202,298.72
GermanyRoad-150 Red, 5243$1,080,637.54
United KingdomRoad-150 Red, 4851$1,205,876.99
United KingdomRoad-150 Red, 6252$1,202,298.72
United KingdomRoad-150 Red, 5253$1,080,637.54
United StatesRoad-150 Red, 4861$1,205,876.99
United StatesRoad-150 Red, 6262$1,202,298.72
United StatesRoad-150 Red, 5263$1,080,637.54

你可能感兴趣的:(with)