CurrentOrdinal (MDX)
返回迭代过程中集内的当前迭代数。
语法
Set_Expression.CurrentOrdinal
参数
- Set_Expression
返回集的有效多维表达式 (MDX)。
注释
当遍历一个集(例如使用 Filter (MDX) 或 Generate (MDX) 函数)时,CurrentOrdinal 函数返回迭代数。
示例
以下简单示例说明如何将 CurrentOrdinal 与 Generate 一起使用来返回字符串,该字符串包含集中每项的名称以及它在该集中的位置:
WITH SET MySet AS [Customer].[Customer Geography].[Country].MEMBERS
MEMBER MEASURES.CURRENTORDINALDEMO AS
GENERATE(MySet, CSTR(MySet.CURRENTORDINAL) + ") " + MySet.CURRENT.ITEM(0).NAME, ", ")
SELECT MEASURES.CURRENTORDINALDEMO ON 0
FROM [Adventure Works]
CurrentOrdinal 的实际用法仅限于非常复杂的计算。下例将返回集中唯一产品的数目,其中使用了 Order 函数以在使用 Filter 函数前对非空元组进行排序。CurrentOrdinal 函数用于比较和消除等同值。
WITH MEMBER [Measures].[PrdTies] AS Count
(Filter
(Order
(NonEmpty
([Product].[Product].[Product].Members
, {[Measures].[Reseller Order Quantity]}
)
, [Measures].[Reseller Order Quantity]
, BDESC
) AS OrdPrds
, NOT((OrdPrds.CurrentOrdinal < OrdPrds.Count
AND [Measures].[Reseller Order Quantity] =
( [Measures].[Reseller Order Quantity]
, OrdPrds.Item
(OrdPrds.CurrentOrdinal
)
)
)
OR (OrdPrds.CurrentOrdinal > 1
AND [Measures].[Reseller Order Quantity] =
([Measures].[Reseller Order Quantity]
, OrdPrds.Item
(OrdPrds.CurrentOrdinal-2)
)
)
))
)
SELECT {[Measures].[PrdTies]} ON 0
FROM [Adventure Works]