Friday, July 29, 2011

INF: MDX: How to Query for the 10 Best Customers and the Top 5 Products for Each Customer

INF: MDX: How to Query for the 10 Best Customers and the Top 5 Products for Each Customer: "--The top 10 customers can be defined in a named set, using the TopCount
--function to limit the set and to return the names of the customers with
--the 10 highest Units Sales for the year 1997.

WITH SET Top10Cust AS
'TopCount( { [Customers].[Name].Members }, 10, ([Time].[1997], [Unit Sales]) )'

--Then use the Generate and CrossJoin functions in the body of the query
--to combine the Top10Cust Named Set with the top 5 products for those
--customers.

SELECT { [Time].[1997] } ON COLUMNS ,
Generate( {Top10Cust}, CrossJoin( {Customers.CurrentMember},
TopCount([Product].[Product Name].Members, 5, ([Time].[1997], [Unit Sales])))) ON ROWS
FROM [Sales]"

No comments: