本文提供了一种在应用RANK
时忽略null的方法:http://www.bidn.com/blogs/CraigLove/ssas/2617/mdx-walkthrough
有没有比使用CASE
更优雅的方式?
WITH
MEMBER [Measures].[City Rank]
AS
CASE
WHEN
NOT ISEMPTY
(
(
[Geography].[City].CurrentMember
,[Measures].[Reseller Sales Amount]
)
)
THEN
RANK
(
[Geography].[City].CurrentMember
,[Geography].[City].AllMembers
,[Measures].[Reseller Sales Amount]
)
ELSE
NULL
END
SET [OrderedCity]
AS
ORDER
(
[Geography].[City].AllMembers
,[Measures].[Reseller Sales Amount]
,DESC
)
SELECT
{
[Measures].[City Rank]
,[Measures].[Reseller Sales Amount]
} ON COLUMNS
,NON EMPTY [OrderedCity] ON ROWS
FROM [Adventure Works];
答案 0 :(得分:1)
您可以在NonEmpty
中应用OrderedCity
功能:
WITH
SET [OrderedCity]
AS
NonEmpty(
ORDER
(
[Geography].[City].AllMembers
,[Measures].[Reseller Sales Amount]
,DESC
)
)
MEMBER [Measures].[City Rank]
AS
RANK
(
[Geography].[City].CurrentMember
,[OrderedCity]
)
SELECT
{
[Measures].[City Rank]
,[Measures].[Reseller Sales Amount]
} ON COLUMNS
,[OrderedCity]
ON ROWS
FROM [Adventure Works];
这样,NON EMPTY
在它放在那里之前就被应用在行上的集合上,因此不需要在行本身上应用它。此外,在City Rank
的定义中重用集合允许Analysis Services仅计算一次排序,并缓存有序集。否则,Rank
将要求为每一行重新计算排序。