MDX #2 – Top (n) Products Sales in each Sales Territory

To get top (n) products with highest sales in every sales territory, the GENERATE function is exactly what we need which applies a set to each member of another set.

SELECT
	{[Measures].[Reseller Sales Amount]} ON Columns,
	GENERATE(
		[Sales Territory].[Sales Territory].[Country].MEMBERS
		,TOPCOUNT([Sales Territory].[Sales Territory].CURRENTMEMBER
			*[Product].[Product].[Product].MEMBERS
			,5
			,[Measures].[Reseller Sales Amount]
		)
	) ON ROWS
FROM [Adventure Works]

MDX03

Leave a comment