Export (0) Print
Expand All

TopCount

Returns the specified number of top-most rows in decreasing order of rank as specified by an expression.


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

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

<table expression>

The value that is supplied by the <rank expression> argument determines the decreasing order of rank for the rows that are supplied in the <table expression> argument, and the number of top-most rows that is specified in the <count> argument is returned.

For example, assume that the following Sub-SELECT statement returns the table below:

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

Product name Probability

Apples

0.4

Kiwi fruit

0.1

Oranges

0.5

Lemons

0.2

The TopCount function can be used with the Sub-SELECT statement as follows:

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

This example yields the following results:

Product name Probability

Oranges

0.5

Apples

0.4

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft