Unlocking the Mystery of MDX

665 views

Published on

Despite widespread adoption of OLAP technologies, the MDX query language remains a bit of an enigma. It's not until a very simple but seldom explored concept is understood that the power and elegance of the language is revealed. Join Bryan Smith, co-author of Microsoft SQL Server 2008 MDX Step by Step, in exploring this central concept, providing a foundation for your success with the MDX language.

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
665
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Unlocking the Mystery of MDX

  1. 1. Unlocking theMystery of MDX Bryan Smith brysmi@microsoft.com
  2. 2. Objectives Obj tiExplain h d behindE l i the modell b hi d MDX Explore lessons learned
  3. 3. The iTh views and opinions expressed in this .... d ii d i thi
  4. 4. (3) x-4 -3 -2 -1 0 1 2 3 4
  5. 5. y 4 (3, 2) 3 2 1 x-4 -3 -2 -1 1 2 3 4 -2 -3 -4
  6. 6. y 4 (3, 2, 4) 3 2 1 x-4 -3 -2 -1 1 2 3 4 -2z -3 -4
  7. 7. one-dimensional (x) singletwo-dimensional (x, y) doublethree-dimensionall h di i (x, ) ( y, z) triple il (a1, a2, a3, a4)four-dimensional (x, y, z, ?) quadruple
  8. 8. four-dimensionalf di i l (a ( 1 , a2 , a3 , a4 ) quadruple d lfive-dimensional (a1, a2, a3, a4, a5) quintuplesix-dimensional (a1, a2, a3, a4, a5, a6) sextupleseven-dimensional (a1, a2, a3, a4, a5, a6, a7) septupleeight dimensionaleight-dimensional (a1, a2, a3, a4, a5, a6, a7, a8) octuple
  9. 9. four-dimensionalfour dimensional (a1, a2, a3, a4) quadruplefive-dimensional (a1, a2, a3, a4, a5) quintuplesix-dimensional (a1, a2, a3, a4, a5, a6) sextupleseven-dimensional (a1, a2, a3, a4, a5, a6, a7) septupleeight dimensionaleight-dimensional (a1, a2, a3, a4, a5, a6, a7, a8) octuplen-dimensional (a1, a2, … an) tuple
  10. 10. My Simple Cube Measure Group Σ Measure Dimension Attribute
  11. 11. My Simple Cube Reseller Sales Internet Sales6 Σ Reseller Sales Amount Σ Internet Sales Amount Date Product Geography 1 Fiscal Year 3 Category 5 Country 2 Calendar Year 4 Subcategory
  12. 12. ProductP d t Category All Products Accessories Bikes Clothing Components
  13. 13. Components C ([Bikes]) Clo othing Bike es Accessories A Alll Products Category [Product].[Category]P d tProduct
  14. 14. ( ( a1, [CY 2002], [Date].[Calendar Year].[CY 2002], [All Periods], a2, [Date].[Fiscal Year].[All Periods], [Bikes], a3, [Product].[Category].[Bikes], [All Products], a4, [Product].[Subcategory].[All Products], [All Geographies], a5, [Geography].[Country].[All Geographies], [Reseller Sales Amount] a6 [Measures].[Reseller Sales Amount] ) )( [Geography].[Country].[All Geographies], [Product].[Category].[Bikes], [Measures].[Reseller Sales Amount], [ ][ [Date].[Fiscal Year].[All Periods], ][ ] [Product].[Subcategory].[All Products], [Date].[Calendar Year].[CY 2002])
  15. 15. (( [Date].[Calendar Year].[CY 2002], [Date].[Calendar Y ] [CY [D ] [C l d Year].[CY 2002], ] [ ][ [Date].[Fiscal Year].[All Periods], ][ ], [Product].[Category].[Bikes] [Product].[Category].[Bikes]) [Product].[Subcategory].[All Products], [Geography].[Country].[All Geographies], [Measures].[Reseller Sales Amount] ) Attributes Partial Rule 1 Rule 2 Rule 3 Completed Tuple Default Member (All) Member First Member Tuple Date.Calendar Year CY 2002 CY 2002 Date.Fiscal Year All Periods All Periods Product.Category Bikes Bikes Product.Subcategory All Products All Products Geography.Country All Geographies All Geographies Measures Reseller Sales Amount Reseller Sales Amount
  16. 16. SELECT [Date].[Calendar Year].Members ON COLUMNS, [Product].[Category].Members ON ROWS FROM [My Simple Cube] All Periods CY 2001 CY 2002 CY 2003 CY 2004All Products $80,450,597 $8,065,435 $24,144,430 $32,202,669 $16,038,063Accessories $571,298 $20,235 $92,735 $296,533 $161,794Bikes $66,302,382 $7,395,349 $19,956,015 $25,551,775 $13,399,243Clothing $1,777,840 $34,376 $485,587 $871,864 $386,013Components $11,799,077 $34,376 $3,610,092 $5,482,497 $2,091,012
  17. 17. MDX SELECT [Date].[Calendar Y ] M b [D ] [C l d Year].Members ON COLUMNS, COLUMNS [Product].[Category].Members ON ROWS FROM [My Simple Cube]SQL SELECT e.CalendarYear, d.EnglishProductCategoryName, SUM(a.SalesAmount) FROM FactResellerSales a INNER JOIN DimProduct b ON a.ProductKey=b.ProductKey d b d INNER JOIN DimProductSubcategory c ON b.ProductSubcategoryKey=c.ProductSubcategoryKey INNER JOIN DimProductCategory d ON c.ProductCategoryKey=d.ProductCategoryKey INNER JOIN DimDate e ON a.OrderDateKey=e.DateKey GROUP BY e.CalendarYear, d.EnglishProductCategoryName
  18. 18. MDX WITH MEMBER [Measures].[Total Sales Amount] AS [Measures].[Internet Sales Amount] + [Measures].[Reseller Sales Amount] [M ] [I Sl A ] [M ] [R ll S l A ] SET [Top 10 Products of 2003] AS TOPCOUNT( [Product].[Product].[Product].Members, 10, ([Measures].[Total Sales Amount], [Date].[Calendar Year].[CY 2003]) ) SELECT [Measures].[Total Sales Amount] ON COLUMNS, [Top 10 Products of 2003] ON ROWS FROM [Step-by-Step] WHERE ([Date].[Calendar Year].[CY 2004])SQL SELECT m.EnglishProductName, o.TotalSalesAmount FROM dbo.DimProduct m INNER JOIN ( -- TOP 10 PRODUCTS OF 2003 SELECT TOP 10 a.ProductKey, SUM(a.SalesAmount) AS TotalSalesAmount d ( l ) l l FROM ( SELECT x.productkey, x.salesamount FROM dbo.FactInternetSales x INNER JOIN dbo.DimDate y ON x.OrderDateKey=y.DateKey WHERE y.CalendarYear=2003 UNION ALL SELECT x.productkey, x.salesamount
  19. 19. Lessons Learned L L d Clearly d fi Cl l define audience diAlign technology with audience Actively engage audience
  20. 20. Thank You!brysmi@microsoft.com

×