CurrentOrdinal (MDX)

New: 17 July 2006

Returns the current iteration number within a set during iteration.




  • Set_Expression
    A valid Multidimensional Expressions (MDX) expression that returns a set.


When iterating through a set, such as with the Filter (MDX) or Generate (MDX) functions, the CurrentOrdinal function returns the iteration number.


The specified set must be an alias and cannot be a named set.


The following example returns the number of products in the set that are unique, using the Order function to order the non-empty tuples before utilizing the Filter function. The CurrentOrdinal function is used to compare and eliminate ties.

WITH MEMBER [Measures].[PrdTies] AS Count
          , {[Measures].[Reseller Order Quantity]}
       , [Measures].[Reseller Order Quantity]
       , BDESC
       ) AS OrdPrds
    , (OrdPrds.CurrentOrdinal < OrdPrds.Count 
       AND [Measures].[Reseller Order Quantity] = 
          ( [Measures].[Reseller Order Quantity]
            , OrdPrds.Item
         OR (OrdPrds.CurrentOrdinal > 1 
            AND [Measures].[Reseller Order Quantity] = 
               ([Measures].[Reseller Order Quantity]
               , OrdPrds.Item
SELECT {[Measures].[PrdTies]} ON 0
FROM [Adventure Works]

See Also


MDX Function Reference (MDX)

Help and Information

Getting SQL Server 2005 Assistance

Change History

Release History

17 July 2006

Changed content:
  • Updated syntax and arguments to improve clarity.
  • Added updated examples.