我使用以下内容:
WITH
SET [myset] AS
Order
(
{
[Customer].[Country].[Country].MEMBERS
*
[Customer].[Customer].[Customer].MEMBERS
}
,[Measures].[Internet Sales Amount]
,ASC
)
MEMBER [Measures].[rank] AS
Rank
(
(
[Customer].[Country].CurrentMember
,[Customer].[Customer].CurrentMember
)
,[myset]
)
MEMBER [Measures].[newrank] AS
IIF
(
[myset].Item(
[Measures].[rank] - 1).Item(0).Name
<>
[myset].Item(
[Measures].[rank] - 2).Item(0).Name
,1
,
([myset].Item([Measures].[rank] - 2),[Measures].[newrank]) + 1
)
SELECT
{
[Measures].[Internet Sales Amount]
,[Measures].[rank]
,[Measures].[newrank]
} ON 0
,[myset] ON 1
FROM [Adventure Works];
这是Amish Shah的作品:http://blog.sqltechie.com/2010/03/rank-with-partitioning-mdx.html
目前它没有给出具有相同排名的元组的元组,例如如果x的互联网销售额为10且y也有10,则在上面它们的排名不会相同。
上述内容是否可以更改,以便它们具有相同的值,那么它们对[Measures].[rank]
具有相同的值 - 并且[Measures].[newrank]
的值也相同?
(在[Measures].[rank]
的定义中添加第三个参数似乎不是一个可行的路径,因为Rank函数然后进入逐个单元计算模式)
答案 0 :(得分:0)
如何使用递归计算成员 -
WITH
SET [myset] AS
Order
(
{
[Customer].[Country].[Country].MEMBERS
*
[Customer].[Customer].[Customer].MEMBERS
}
,[Measures].[Internet Sales Amount]
,ASC
)
MEMBER [Measures].[myrank] AS
Rank
(
(
[Customer].[Country].CurrentMember
,[Customer].[Customer].CurrentMember
)
,[myset]
)
member prevmembervalue as
(myset.item(myRank - 2), [Measures].[Internet Sales Amount])
member currentmembervalue as
(myset.item(myRank - 1), [Measures].[Internet Sales Amount])
MEMBER greaterthanprev as
iif(currentmembervalue > prevmembervalue, 1, 0)
member rankActual as
iif
(
prevmembervalue = null, 1,
iif(currentmembervalue > prevmembervalue,
(myset.item(myRank - 2), rankActual) + 1,
(myset.item(myRank - 2), rankActual)
)
)
select myset on 1,
{[Measures].[Internet Sales Amount], rankActual, myRank}
on 0
from
[Adventure Works]
实际上不需要greaterthanprev
,currentmembervalue
和prevmembervalue
这些措施。在这里添加它们只是为了进一步澄清过程。