Returns: A set.
>>-TopSum--(--SetExpression--,--Sum--+--------------------------+--)->< '-,--+-NumericExpression-+-' '-StringExpression--'
The TopSum function always breaks the hierarchy; that is, the members of the set are always sorted without regard to their positions in the hierarchy.
In this example you want to see which stores have the highest profit amounts that make up 100000 in profits. The following query uses the TopSum function to return the profit amount of stores that have the largest profit amounts whose total is at least 100000. The stores are organized in descending order of profit amount.
SELECT {[Price Analysis].[Measures].[Profit Amount]}
ON AXIS(0),
{TopSum(Descendants([Price Analysis].[Store].[All Stores], -1, LEAVES),
100000,
[Price Analysis].[Measures].[Profit Amount])}
ON AXIS(1)
FROM [Price Analysis]
| Store | Profit amount |
|---|---|
| ValueTrend Store 1199 | 84813.24 |
| ValueTrend Store 116 | 81950.42 |
You can use the BottomSum function to find the smallest values in a set that compose a certain sum.
You can use the TopCount function to find a specified number of the largest values in a set, or you can use the TopPercent function to find the largest values in a set that compose a certain percent of the total of the values of the set.
The TopSum function sorts sets in the same way that the Order function does with the BDESC flag specified: that is, the function breaks hierarchies and sorts in descending order.