• subscribe
September 21, 2000 12:00 AM

May MDX Puzzle Solution Revealed

SQL Server Pro
InstantDoc ID #8667

How would you write an MDX query that returns the top three promotions for each state in the United States for 1997? Format the result so that 1997 is the only column and the states are on the rows, with the top three promotions nested in each state.



SELECT {[1997]} ON COLUMNS,
   GENERATE( [All Customers].[USA].Children, {[Customers].CurrentMember} *
             TOPCOUNT( [Promotion Name].Members, 3, [Customers].CurrentMember) ) ON ROWS
FROM [Sales]

Screen A shows the result of this query. The Generate function is the key to this puzzle. The Generate function determines the top three promotions for each state independently; of course, the list of top promotions can be different for each state. The Generate function evaluates its second parameter (the TopCount formula) independently for each set item in the first parameter (the states in the United States). The Generate function unions the results of each evaluation of the TopCount formula.



ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...