Skip to main content

TopCount

Sorts a specified set in descending order, and returns a specified number of elements with the highest values.

Syntax

TopCount(Set_Expression,Count [ ,Numeric_Expression ] )  

Input parameters

Set_Expression

An MDX expression that returns a set.

Count

The number of tuples to return.

Numeric_Expression

Optional. An MDX expression defining cell coordinates that return a number.

If this value is specified, the set is sorted in descending order according to the value of this expression as evaluated over the set. TopCount then returns the specified number of elements with the highest values.

If this value is not specified, TopCount returns the set without sorting, similar to the Head function.

Example

The following example sorts the expression [Product].[Product Categories].AllMembers in descending order according to the value specified by [Measures].[Internet Sales Amount Local], and returns the tuples with the 10 highest values:

TopCount(
[Product].[Product Categories].AllMembers,
10,
[Measures].[Internet Sales Amount Local]
)