TopCount

Analysis Services Programming

Analysis Services Programming

TopCount

The TopCount function returns the specified number of topmost rows in a decreasing order of rank as specified by an expression.

Syntax

TopCount(<table expression>, <rank expression>, <count>)

Applies to

An expression that returns a table, such as a <table column reference> or a function that returns a table.

Return Type

<table expression>

Remarks

The value supplied by the <rank expression> argument is used to determine the decreasing order of rank for the rows supplied in the <table expression> argument, and the number of topmost rows specified in the <count> argument is returned.

For example, assume that this Sub-SELECT contains the following table:

(SELECT [Product Name], $Probability AS [Probability] FROM Predict([Products Purchases], INCLUDE_STATISTICS))

Product Name Probability
Apples 0.4
Kiwi 0.1
Oranges 0.5
Lemons 0.2

Using the TopCount function with the Sub-SELECT as a parameter as shown yields the following results:

TopCount((SELECT [Product Name], $Probability AS [Probability] FROM Predict([Products Purchases], INCLUDE_STATISTICS)), [Probability], 2)
Product Name Probability
Oranges 0.5
Apples 0.4