如何在相同的mdx中使用两个维度获得前2个计数记录和休息总数(其他)

时间:2014-08-11 11:10:17

标签: ssas mdx

我有这个查询,我需要实现二维

WITH
SET [TCat] AS
TopCount([Product].[Subcategory].[Subcategory],10,[Measures].[Sales Amount])
MEMBER [Product].[Subcategory].[Other] AS
Aggregate([Product].[Subcategory].[Subcategory] - TCat)

SELECT { [Measures].[Sales Amount] } ON COLUMNS,
TCat + [Other] ON ROWS
FROM [Adventure Works]

我尝试但它不适用于二维

WITH 
SET FIPS as
  [Geography].[State-Province].[State-Province]
//TopCount([Product].[Subcategory].[Subcategory],10,[Measures].[Sales Amount])
SET [TCat] AS 
  Generate( {FIPS}, CrossJoin( {[Geography].[State-Province].CurrentMember}, topsum( ([Product].[Subcategory].[Subcategory]), 2, [Measures].[Sales Amount] ) ))   
MEMBER [Product].[Subcategory].[Other] AS 
  Aggregate(Except( [Product].[Subcategory].[Subcategory].Members, TCat))
SELECT 
  { [Measures].[Sales Amount] } ON COLUMNS, 
  Union( 
     TCat , {[Geography].[State-Province].[State-Province],[Product].[Subcategory].[Other]} ) ON ROWS 
FROM [Adventure Works];

1 个答案:

答案 0 :(得分:0)

尝试使用Except。

WITH
SET [TCat] AS
TopCount([Product].[Subcategory].[Subcategory],10,[Measures].[Sales Amount])
MEMBER [Product].[Subcategory].[Other] AS
Aggregate(Except( [Product].[Subcategory].[Subcategory].Members, TCat)

SELECT { [Measures].[Sales Amount] } ON COLUMNS,
Union( TCat , {[Product].[Subcategory].[Other]} ) ON ROWS
FROM [Adventure Works]