Head function (MDX)

The Head function returns a specified number of elements from the beginning of a set.

Returns: A set.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-Head--(--SetExpression--+----------------------+--)---------><
                           '-,--NumericExpression-'      

Parameters

SetExpression
Specifies an expression that returns a set.
NumericExpression
Specifies a numeric expression that specifies the number of elements within a set that you want returned.

If you do not specify a numeric expression, the default value is 1. If you specify a number that is greater than the number of elements in a set, the complete original set is returned. If you specify a numeric expression that is less than 1, an empty set is returned.

Description

Use the Head function to return a specific number of elements starting from the beginning of a set. The order of elements that are returned is maintained within the new set.

Example

In this example, you want to see which stores are the most profitable. The following query uses the Head function to return the profit amount of the three stores that have the largest profit amounts.

Query
SELECT {[Price Analysis].[Measures].[Profit Amount]} 
          ON AXIS(0), 
       {Head(Order(Descendants([Price Analysis].[Store].[All Stores], -1, LEAVES),
                    [Price Analysis].[Measures].[Profit Amount], BDESC), 3)} 
          ON AXIS(1)
FROM [Price Analysis]
Result
Store Profit amount
ValueTrend Store 1199 84813.24
ValueTrend Store 116 81950.42
ValueTrend Store 1095 81673.1

Related functions

You can use the Tail function to get a specified number of elements from the end of a set.

You can use the Subset function to get a specified number of elements from any part of a set.



Feedback | Information roadmap