Mdx 2nddraft

1,872 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,872
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
233
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • MoshaPasumansky, a former Panorama developer who is credited with being the primary author of the language
  • Mdx 2nddraft

    1. 1. MDX LanguageAn Overview<br />Presented by: <br />Muhammad Saleh AL-Qurishi FatoohAL-Qershi<br />
    2. 2. Agenda<br />Introduction<br />Brief History<br />SQL vs. MDX<br />MDX Language<br />MDX syntax<br />Naming conventions<br />Tuples and sets<br />How MDX is used<br />MDX queries<br />Using MDX for queries<br />SELECT, FROM, ON COLUMNS, ON ROWS<br />WHERE<br />MDX expression<br />References<br />2<br />12/30/2009<br />MDX Solution Presentation By-Muhammad & Fatooh<br />
    3. 3. MDX Solution Presentation By-Muhammad & Fatooh<br />3<br />12/30/2009<br />Introduction<br />
    4. 4. Brief History<br />MDX Solution Presentation By-Muhammad & Fatooh<br />4<br />12/30/2009<br />When first conceived of by Panorama Software in the mid-1990s, MDX was an extension of SQL. <br />Its original name was Multi-Dimensional eXtensions, <br />(says MoshaPasumansky)<br />In less than a decade, the programming language MDX has become the de facto standard for reporting and analysis in business intelligence (BI) systems<br />It is supported by virtually every major vendor of BI servers, including Microsoft, SSAS, IBM, Hyperion, and SAP<br />
    5. 5. Why has MDX become so popular<br />The growth of the BI industry it self.<br />Users need fast and intuitive access to company information to make more profitable business decisions<br />It is uniquely able to navigate, query, and perform calculations against multidimensional structures<br />MDX Solution Presentation By-Muhammad & Fatooh<br />5<br />12/30/2009<br />
    6. 6. How MDX Differs from SQL?<br />MDX Solution Presentation By-Muhammad & Fatooh<br />6<br />12/30/2009<br />
    7. 7. SQL Does Things that MDX Can’t<br />MDX Solution Presentation By-Muhammad & Fatooh<br />7<br />12/30/2009<br />
    8. 8. MDX Language<br />MDX Solution Presentation By-Muhammad & Fatooh<br />8<br />12/30/2009<br />
    9. 9. What Is MDX?<br />MDX is a language that<br />Expresses selections, calculations, and some metadata definitions against an Online Analytical Processing (OLAP) database <br />Provides some capabilities for specifying how query results are to be represented <br />Is not a full report-formatting language<br />There are several different APIs that support MDX<br />OLE DB for OLAP, ADO MD, ADOMD.Net, XMLA<br />MDX Solution Presentation By-Muhammad & Fatooh<br />9<br />12/30/2009<br />
    10. 10. MDX – Basic Terminology<br />Cube – is a subset of data from the OLAP store, organized and summarized into multidimensional structures<br />Cell – One or more facts (measures) and dimension attributes that represent one record in a cube<br />Dimension – business factor used to group a fact record<br />Hierarchy – Levels of aggregation in a dimension<br />Level – Aggregation layer in a dimension hierarchy<br />Member – value of a dimension attribute or a derived value from a dimension attribute<br />Measure – Fact. Numerical value that measures a business activity and can be summarized <br />MDX Solution Presentation By-Muhammad & Fatooh<br />10<br />12/30/2009<br />
    11. 11. Naming Conventions <br />MDX Solution Presentation By-Muhammad & Fatooh<br />11<br />12/30/2009<br />Working with the Store dimension shown in the diagram above, we’d indicate the Leominster member like this:<br /> [Store].[All].[Massachusetts].[Leominster]<br />[Store].Leominster] with certain data and certain naming conventions<br />if we have a hierarchy of Time we can’t use [Time].[Oct]because we may have more than one October in different years. But we can use [Time].[June,2001] rather than [Time].[All].[2001].[Q2].[June] <br />
    12. 12. Tuples and Sets<br />A tuple is a combination of members from different dimensions<br />Essentially a multidimensional member<br />A single member is a simple tuple<br />([Time].[Jun, 2005]) simple tuple (one dimension)<br />([Customer].[Chicago, IL], [Time].[Jan, 2005]) tuple with two dimensions<br />Each member in the tuple has to be from a different dimension<br />E.g. tuple should not have two Time members<br />We can’t compose an empty tuple<br />We can’t use syntax to compose a tuple from tuples<br />MDX Solution Presentation By-Muhammad & Fatooh<br />12<br />12/30/2009<br />
    13. 13. Tuples and Sets(cont.)<br />A set is simply an ordered collection of tuples<br />Sets are typically enclosed by curled &quot;{ }&quot; braces<br />Specify the cells of a cube that are to be returned by the query <br />Often appear in the SELECT part of a query<br />MDX Solution Presentation By-Muhammad & Fatooh<br />13<br />12/30/2009<br />SELECT<br />{ ( [Time].[2005], [Measures].[Dollar Sales] ),<br />( [Time].[Feb, 2005], [Measures].[Unit Sales] )<br />}<br />ON COLUMNS ,<br />{ [Product].[Tools], [Product].[Toys] } ON ROWS<br />FROM [Sales]<br />
    14. 14. Brackets, braces and the odd dot and comma <br />MDX Solution Presentation By-Muhammad & Fatooh<br />14<br />12/30/2009<br />
    15. 15. Question 1<br />MDX Solution Presentation By-Muhammad & Fatooh<br />15<br />12/30/2009<br />Is the following a tuple or a set?<br />([Time].[May], [Store].[Boston], [Product].[Anchovies])<br />Answer: ?<br />
    16. 16. Question 2<br />OK, now what about these two?<br />1- ([Store].[Boston], [Product].[Anchovies])<br />2- {([Time].[April], [Store].[Boston], [Product].[Anchovies]),<br />([Time].[May], [Store].[Boston], [Product].[Anchovies]),<br />([Time].[June], [Store].[Boston], [Product].[Anchovies]),<br />([Time].[July], [Store].[Boston], [Product].[Anchovies])}<br />Answer:?<br />MDX Solution Presentation By-Muhammad & Fatooh<br />16<br />12/30/2009<br />
    17. 17. How MDX is used<br />MDX Solution Presentation By-Muhammad & Fatooh<br />17<br />12/30/2009<br />
    18. 18. MDX Query Syntax<br />SELECT<br /> {set defining the column headers} <br />ON COLUMNS,<br /> {set defining the row headers} <br />ON ROWS<br />FROM [cube name]<br />WHERE [Slicer specification]<br />MDX Solution Presentation By-Muhammad & Fatooh<br />18<br />12/30/2009<br />MDX is neither case-sensitive nor line-oriented<br />
    19. 19. MDX Query Syntax(cont.)<br />MDX Solution Presentation By-Muhammad & Fatooh<br />19<br />12/30/2009<br />The SELECT keyword starts the clause that specifies what you want to retrieve<br />The ON keyword is used with an axis name to specify where dimensions from our database are displayed<br />If you desire more generic axis terms over the named terms, you can use the AXIS(index) naming convention<br />The phrase on axis(n) indicates that those members should be put on the axis numbered n.<br />A query that uses axis 1 must also use axis 0, and a query that uses axis 2 must also use axes 1 and 0<br />
    20. 20. Query example<br />MDX Solution Presentation By-Muhammad & Fatooh<br />20<br />12/30/2009<br />Look at a grid of numbers that has the Massachusetts sales and costs for the first two quarters of 2005<br />SELECT<br />{ [Measures].[Dollar Sales], [Measures].[Unit Sales] }<br />ON columns,<br />{ [Time].[Q1, 2005], [Time].[Q2, 2005] }<br />ON rows<br />FROM [Sales]<br />
    21. 21. Slicer Clause (WHERE clause)<br />WHERE clause is actually optional<br />It is used to define the measure that is being queried<br />It can, and often does, extend to other dimensions<br />WHERE (Measures.[Sales Average], [Time].[Year].[1997])<br />It is not the same as filtering (such as SQL)<br />Slicing does not affect selection of the axis members, but rather the values that go into them<br />Filtering reduces the number of axis members<br />MDX Solution Presentation By-Muhammad & Fatooh<br />21<br />12/30/2009<br />
    22. 22. Five main execution stages after the query is successfully parsed:<br />1- Resolving the FROM clause<br />2- Resolving the WHERE clause<br />3- Resolving named sets in the WITH clause<br />4- Resolving the tuples on each axis<br />5- Calculating the cells brought back in the axis intersections<br />a. Resolving NON EMPTY intersections<br />b. (AS2005) Resolving the HAVING clause on each axis<br />22<br />12/30/2009<br />MDX Solution Presentation By-Muhammad & Fatooh<br />The Execution Stages of a Query<br />
    23. 23. MDX Expression<br />MDX Solution Presentation By-Muhammad & Fatooh<br />23<br />12/30/2009<br />
    24. 24. Calculated Member<br />The core syntax for defining a calculated member on a dimension is<br />MEMBER MemberIdentifier AS ‘member-formula’ [, properties...]<br />The three main parts are:<br />Member identifier, which specifies the name, dimension and hierarchical positioning of the calculated member<br />Formula, which specifies how the calculated member’s results are derived<br />Optional properties, which can provide additional calculation, display, and other kinds of information<br />MDX Solution Presentation By-Muhammad & Fatooh<br />24<br />12/30/2009<br />
    25. 25. Calculated Member(cont.)<br />Calculated Member in the WITH section of a query will not visible outside of the query.<br />If we use CREATE SET command, then it will be available to more than one query <br />We can drop it with the DROP SET command<br />MDX Solution Presentation By-Muhammad & Fatooh<br />25<br />12/30/2009<br />
    26. 26. Calculated Member(WITH Section)<br />MDX Solution Presentation By-Muhammad & Fatooh<br />26<br />12/30/2009<br />
    27. 27. Calculated Member(more than one dimension)<br />MDX Solution Presentation By-Muhammad & Fatooh<br />27<br />12/30/2009<br />
    28. 28. Named Set<br />The basic syntax for defining a named set that is supported by most vendors is as follows:<br />SETSet-Identifier AS ‘set-formula’<br />Named set in the WITH part of a query will not visible outside of the query.<br />If we use CREATE SET command, then it will be available to more than one query <br />We can drop it with the DROP SET command<br />MDX Solution Presentation By-Muhammad & Fatooh<br />28<br />12/30/2009<br />
    29. 29. Named set using WITH clause<br />MDX Solution Presentation By-Muhammad & Fatooh<br />29<br />12/30/2009<br />
    30. 30. Named set using CREAT SET<br />MDX Solution Presentation By-Muhammad & Fatooh<br />30<br />12/30/2009<br />Analysis Services 2005<br />Essbase V9<br />
    31. 31. Common Functions<br />MDX Solution Presentation By-Muhammad & Fatooh<br />31<br />12/30/2009<br />
    32. 32. .MEMBER<br />The simplest form of an axis specification or member selection involves taking the MEMBERS of the required dimension<br />Returns set of all members<br />MDX Solution Presentation By-Muhammad & Fatooh<br />32<br />12/30/2009<br />SELECT Measures.MEMBERS<br />ON COLUMNS,<br />[Store].MEMBERS <br />ON ROWS<br />FROM [Sales]<br />SELECT Measures.MEMBERS ON COLUMNS,<br />{[Store].[Store State].[CA], [Store].[Store State].[WA]} ON ROWS<br />FROM [Sales]<br />
    33. 33. . CHILDREN<br />Returns the set of all members of the level immediately beneath the starting level<br />Returns the child members for a particular member within the dimension<br />MDX Solution Presentation By-Muhammad & Fatooh<br />33<br />12/30/2009<br />SELECT Measures.MEMBERS<br />ON COLUMNS,<br />{[Store].[Store State].[CA].CHILDREN,<br />[Store].[Store State].[WA].CHILDREN} <br />ON ROWS<br />FROM [Sales]<br />
    34. 34. Both MEMBER & CHILDREN functions are used often in formulating expressions, but do not provide the ability to drill down to a lower level within the hierarchy<br />MDX Solution Presentation By-Muhammad & Fatooh<br />34<br />12/30/2009<br />For this task, a function called DESCENDANTS is required<br />This function allows one to go to any level in depth<br />
    35. 35. Descendants()<br />MDX Solution Presentation By-Muhammad & Fatooh<br />35<br />12/30/2009<br />The syntax for the DESCENDANTS function is:<br />DESCENDANTS(member, level [, flags])<br />The expression:<br />Descendants( [Time].[1998],[Month])<br />would return all twelve months 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 and 12 (that is, all the descendants of 1998 at the month level) <br />And:<br />Descendants( [Time].[1998].[Q2],[Month])<br />would return all the descendants of Q2 at the month level, namely 4, 5 and 6<br />
    36. 36. CrossJoin()<br />CrossJoin() –cross-product of members or tuples in two different sets<br />Specify all possible combinations<br />Syntax: CrossJoin (set1, set2)<br />MDX Solution Presentation By-Muhammad & Fatooh<br />36<br />12/30/2009<br />
    37. 37. Filter()<br />Reduce a set by including in the resulting set only those elements that meet some criteria<br />Arguments<br />Boolean Expression<br />Set<br />Returns subset<br />The syntax for Filter() is:<br />Filter (set, Boolean-expression)<br />For example, the expression<br />Filter (<br /> { [Product].[Product Category].Members }, <br /> [Measures].[Dollar Sales] &gt;= 500 <br /> )<br />MDX Solution Presentation By-Muhammad & Fatooh<br />37<br />12/30/2009<br />
    38. 38. Order()<br />To put the tuples in a set into a sequence based on associated data values<br />The syntax for the Order() function<br />Order (set1, expression [, ASC | DESC | BASC | BDESC])<br />Arguments<br />Ordering criterion<br />Set<br />Flag option (ex. Ascending, descending)<br />Hierarchical order can be complex<br />MDX Solution Presentation By-Muhammad & Fatooh<br />38<br />12/30/2009<br />
    39. 39. Order() Example<br />Given the set of product categories , we may want to sort them in descending order by sales. A very simple query for this may look like the following;<br />MDX Solution Presentation By-Muhammad & Fatooh<br />39<br />12/30/2009<br />
    40. 40. NON EMPTY<br />Removing empty slices from query results<br />Works on any axis, and with any dimensions and tuples<br />MDX Solution Presentation By-Muhammad & Fatooh<br />40<br />12/30/2009<br />
    41. 41. NON EMPTY<br />MDX Solution Presentation By-Muhammad & Fatooh<br />41<br />12/30/2009<br />Query with empty slices on rows<br />Empty slices removed with NON EMPTY<br />
    42. 42. References <br />MDX Solutions, Second Edition: With Microsoft® SQL Server™ Analysis Services 2005 and Hyperion® Essbase<br />Fast Track to MDX by Mark Whitehorn, Robert Zare and MoshaPasumansky<br />MDX language reference<br />http://msdn.microsoft.com/en-us/library/ms145506.aspx<br />http://www.databasejournal.com/article.php/1459531<br />MDX Solution Presentation By-Muhammad & Fatooh<br />42<br />12/30/2009<br />
    43. 43. Thanks<br />?<br />43<br />MDX Solution Presentation By-Muhammad & Fatooh<br />12/30/2009<br />

    ×