CurrentOrdinal (MDX)

New: 17 July 2006

Returns the current iteration number within a set during iteration.

Syntax

Set_Expression.CurrentOrdinal

Arguments

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

Remarks

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

Note

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

Example

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
   (Filter
      (Order
        (NonEmpty
          ([Product].[Product].[Product].Members
          , {[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
               (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]

See Also

Reference

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.