# CurrentOrdinal (MDX)

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

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.

### Examples

The following simple example shows how CurrentOrdinal can be used with Generate to return a string containing the name of each item in a set along with its position in the set:

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

The practical use of CurrentOrdinal is limited to very complex calculations. 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
, 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
```