MDX Functions: TopCount

The MultiDimensional eXpressions, or MDX, language is used to query the data in a multidimensional in an OLAP database.  In the case of examples here, SQL Server Analysis Services. This example uses the Contoso demo cube available for download here:

Function Name: TopCount

Use Case: Brings back the highest X number of values from a set

MSDN Link:

Notes: Always breaks a hierarchy

Syntax: TOPCOUNT(<<MDX Set>>, Number of Tuples to return, <<Measure>>)

Sample Query:

[Measures].[Online Sales Amount]
[Product].[Product Category].CHILDREN,
[Measures].[Online Sales Amount]
FROM [Contoso]

Sample Results:

Bradley Schacht

Bradley Schacht is a Cloud Solution Architect on the state and local government team with Microsoft based in Jacksonville, FL. He has co-authored 3 SQL Server books including "SQL Server 2014 Professional Administration". As a former consultant and trainer, he uses his experience on many parts of the Microsoft BI and data platform to help customers deliver the best possible solutions. Bradley frequently presents at community events around the country. He is a contributor to sites such as and an active member of the Jacksonville SQL Server User Group (JSSUG).

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.