我有这个MDX查询:
WITH
MEMBER [COUNT_RANK] AS
RANK(([TKT].[SP].CURRENTMEMBER,
[TKT].[SA].CURRENTMEMBER) ,
[TKT].[SP].CURRENTMEMBER
*[TKT].[SA].[SA]
)
SELECT {
[COUNT_RANK],
[Measures].[TKT Count],
[Measures].[Est Hours]
} ON 0,
ORDER ({[TKT].[SP].[SP]} * {[TKT].[SA].[SA]}, [Measures].[TKT Count], DESC)
ON 1
FROM Ops
我遇到的问题是,尽管COUNT_RANK
可以正常工作,并且为每个SP
每SA
提供1-to-n的排名值,但我需要基于排名的顺序在TKT Count desc
上。对于rank = 1
而言,则SP * SA必须具有最高数量的TKT。
现在,结果是RANKING的随机TKT计数。如何根据TKT计数DESC来确定RANK?
这是针对SQL Server 2016 SSAS的。谢谢。
答案 0 :(得分:1)
在MSDN Docs中,应该在声明RANK()成员之前创建一个有序集,并在有序集上使用RANK函数。
这是他们的例子:
WITH
SET OrderedCities AS Order
([Geography].[City].[City].members
, [Measures].[Reseller Sales Amount], BDESC
)
MEMBER [Measures].[City Rank] AS Rank
([Geography].[City].CurrentMember, OrderedCities)
SELECT {[Measures].[City Rank],[Measures].[Reseller Sales Amount]} ON 0
,Order
([Geography].[City].[City].MEMBERS
,[City Rank], ASC)
ON 1
FROM [Adventure Works]