下面的询问计算出一项衡量日期最后2年金额的措施:
WITH
MEMBER [Measures].[Sales from the last 2 Years]
AS Aggregate( Tail( [Date].[Calendar Year].[Calendar Year].Members, 2)
, [Measures].[Internet Sales Amount]
)
SELECT { [Measures].[Sales from the last 2 Years]
} ON COLUMNS
, { Tail( [Date].[Calendar Year].[Calendar Year].Members, 2)
} ON ROWS
FROM [Adventure Works]
其他有趣的询问,将计算每年及以往的总额:
WITH
MEMBER [Measures].[Sales from 2 years]
AS Aggregate( { [Date].[Calendar Year].CurrentMember.PrevMember
: [Date].[Calendar Year].CurrentMember }
, [Measures].[Internet Sales Amount]
)
SELECT { [Measures].[Internet Sales Amount]
, [Measures].[Sales from 2 years]
} ON COLUMNS
, NON EMPTY
{ [Date].[Calendar Year].[Calendar Year]
} ON ROWS
FROM [Adventure Works]
It does a sum, because the aggregation type of the measure [Measures].[Internet Sales Amount]
is Sum
, and the Aggregate
function aggregates according to the measure s aggregation type.
MDX是一个难以掌握的议题;如果你重新开始,我建议你读到https://rads.stackoverflow.com/amzn/click/com/0471748080” rel=“nofollow noreferer”>。 MDX Solutions, 2nd edition 。