150 likes | 277 Views
Dive into the world of MDX (Multidimensional Expressions) and learn how to effectively use the WITH clause to define calculated members and named sets. Understanding the foundational structure of MDX queries can significantly enhance your data analysis skills in SQL Server Reporting Services (SSRS). This guide covers basic query syntax, how to create reusable sets and calculations, and demonstrates practical examples to improve readability and simplify complex queries. Discover essential functions like Rank and Item to manipulate data in your queries.
E N D
Think Outside the Group! Erika Bakse @BakseDoesBI erikasblog.datainspirations.com
Outline MDX Query With Clause Named Sets Calculated Members “Location” Functions Think Outside the Group!
MDX Query The basic structure of the MDX query NB: In SSRS queries the columns MUST be measures
Basic Query Syntax SELECT <Set> ON COLUMNS, <Set> ON ROWSFROM <Cube> WHERE <Members>
With Clause Where the fun happens! Create sets, members, measures
With Clause Syntax Add as many calculations as you need in WITH clause WITH MEMBER Measures.MyMeasure AS <expression> SET MySetAS <expression> SELECT <Set> ON COLUMNS, <Set> ON ROWSFROM <Cube> WHERE <Members> Reference calculations directly or indirectly on columns or rows or in WHERE clause
Named Sets WITH MEMBER MemberNameAS <expression> SET MySetAS <expression> SELECT <Set> ON COLUMNS, <Set> ON ROWSFROM <Cube> WHERE <Members>
Named Sets Set expression assigned to an alias Can be used throughout query wherever a set is usable Improve readability Simplify query changes
Calculated Members WITH MEMBER MemberNameAS <expression> SET MySetAS <expression> SELECT <Set> ON COLUMNS, <Set> ON ROWSFROM <Cube> WHERE <Members>
Calculated Members MemberNameis the fully qualified name of the calculated member, including the dimension Commonly used to create calculated measures Can really be defined as just about anything…
“Location” Functions • Where is a tuple “located” in a set? • Rank() • 1-based index • Rank(<TupleExpression>, <SetExpression>) • Return a tuple from a particular location in a set • Item • 0-based index • <SetExpression>.Item(Index)
Resources Creating Named Sets http://msdn.microsoft.com/en-us/library/aa216742(v=sql.80).aspx Creating Calculated Members http://msdn.microsoft.com/en-us/library/aa216747(v=SQL.80).aspx MDX Essentials, William Pearson http://www.databasejournal.com/features/mssql/article.php/1495511/MDX-at-First-Glance-Introduction-to-SQL-Server-MDX-Essentials.htm