7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
1/37
Alex Whittles
PurpleFrogSystems.comPurpleFrogSystems.com/blog
Twitter: @Pu
rpleFrogSys
MDX 101
Now its Multi-Dimensional
mailto:[email protected]://www.purplefrogsystems.com/http://www.purplefrogsystems.com/bloghttp://localhost/var/www/apps/conversion/tmp/scratch_6/Twitter.com/PurpleFrogSyshttp://localhost/var/www/apps/conversion/tmp/scratch_6/Twitter.com/PurpleFrogSyshttp://localhost/var/www/apps/conversion/tmp/scratch_6/Twitter.com/PurpleFrogSyshttp://www.purplefrogsystems.com/bloghttp://www.purplefrogsystems.com/mailto:[email protected]7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
2/37
Alex Whittles
Business Intelligence ConsultancyData Warehousing Data Quality
OLAP Cubes ETL Systems
Dimensional Modelling Reporting Systems
PASS Chapter Leader in Birmingham, UK
www.SQLMidlands.com
Regular speaker at SQL Bits, SQL Relay, SQL
Saturday, Webinars & PASS Chapters
Run Purple Frog BI Consultancy
MSc in Business Intelligence
http://www.sqlmidlands.com/http://www.sqlmidlands.com/7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
3/37
Location Date
Reading Mon 11th November
Southampton Tue 12th November
Cardiff Wed 13th November
Birmingham Thu 14th
NovemberHemel Hempstead Fri 15th November
Newcastle Mon 25th November
Manchester Tue 26th November
Norwich Wed 27th November
Bristol Thu 28th November
London Fri 29th November
SQLRelay.co.uk
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
4/37
What is MDX?
Query Language
Used to query OLAP Cubes
Love child of SQL and a Rubiks Cube
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
5/37
SQL vs MDX
SELECT CurrencyName, OrderDateKey, OrderQuantity
FROM FactInternetSales fis
INNER JOIN dbo.DimCurrency dc
ON fis.CurrencyKey = dc.CurrencyKey
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
6/37
SQL vs MDX
SELECT
[Currency].[Currency].MEMBERS ON COLUMNS,
[Date].[Calendar].[Year].MEMBERS ON ROWS
FROM [Adventure Works]WHERE [Measures].[Internet Order Count]
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
7/37
Cube Basics
SQL
Server
SSIS
Integration Services
SSRS
Reporting Services
SSAS
Analysis Services
Query using: Excel SSRS
PerformancePoint
MDX
Other tools
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
8/37
Cube Basics
Finance
Database
Sales
Database
Marketing
XLS3rd Party CSV
Data
Warehouse
Cube
Reports
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
9/37
Cube Benefits
Speed
Simplicity
Business Calculation Logic
Drag & Drop
Power of MDX
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
10/37
Dimensions Vs Measures
Dimensions
Usually text
Things you group or filter by
A number of attributes
Measures
Always numbers
Things you add up
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
11/37
The Star Schema
Measures
Dimension
DimensionDimension
Dimension
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
12/37
MDX Basics Query Structure
SELECT { SET } ON COLUMNS,
{ SET } ON ROWSFROM CUBE
WHERE ( TUPLE )
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
13/37
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
14/37
SetSetTuple
MDX Basics Cheat Sheet
MDX SQL Equivalent (ish) Syntax
Measure Column (numeric) [Measures].[xxx]
Dimension Table [Dimension]
Attribute Column (text) [Dimension].[Attribute]
Hierarchy GROUP BY Col1, Col2 [Dimension].[Hierarchy]
Member Row[Dimension].[Attribute].[Member]
[Dimension].[Hierarchy].[Member]
Tuple Multiple WHEREs ( Member, Member, Member, )
Set Union{ Member, Member, Member, }
{ Tuple, Tuple, Tuple, }
Member
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
15/37
Cube Basics - Dimensions
Cubes SQL Equivalent
Dimension Table
Attribute Column
Member Row
Dimension A denormalised business entity
Customer / Product / Date / Employee / etc.
Sourced from a SQL Server table in the data warehouse
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
16/37
Cube Basics - Members
Member
A single item from a dimension attribute
e.g. a Date, a Year, a product, an employee
Set
Multiple members OF THE SAME attribute
e.g. Today & Yesterday
or Customer IDs 123, 2921 and 5234
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
17/37
Cube Basics - Members
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
18/37
Syntax - Members
[Dimension].[Attribute].[Member]
[Date].[Year].[2013]
[Date].[Date].[2013-02-20]
[Customer].[Customer].[Waitrose]
[Customer].[Country].[UK]
[Date].[Year].CURRENTMEMBER
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
19/37
Syntax Member Keys
[Dimension].[Attribute].&[Member]
[Date].[Year].[2013] (Name)
[Date].[Year].&[2013] (Key)
[Date].[Month].[March] (Name)
[Date].[Month].&[3] (Key)
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
20/37
Cube Basics - Sets
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
21/37
Syntax - Sets
{ MEMBER1, MEMBER2, MEMBER3 }
{ [Date].[Year].[2010], [Date].[Year].[2012] }
{ [Date].[Year].[2010] : [Date].[Year].[2012] }
{ null : [Date].[Year].CURRENTMEMBER }
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
22/37
Cube Basics - Tuples
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
23/37
Syntax - Tuples
( MEMBER, MEMBER, )
([Date].[Year].[2012],
[Customer].[Customer].[Waitrose])
([Date].[Year].[2012],
[Customer].[Customer].[Waitrose],[Product].[Product].[Banana])
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
24/37
Cube Basics Tuples revisited!
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
25/37
Cube Basics Tuples revisited!
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
26/37
Cube Basics Sets revisited!
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
27/37
Syntax - Sets
{ MEMBER1, MEMBER2, }
{ (TUPLE1), (TUPLE2), }
{ ([Date].[Year].[2010], [Product].[Product].[Banana])
, ( [Date].[Year].[2012], [Product].[Product].[Apple] ) }
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
28/37
Demo
Basic Queries
SELECT xxx ON COLUMNS
SELECT xxx ON ROWS
MEMBERS
TUPLES
SETS
Basic Calculations
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
29/37
Dimension Navigation
CURRENTMEMBER
The query has context
The current member relevant in the query
[Date].[Year].CURRENTMEMBER
PREVMEMBER
The one before to the current member [Date].[Year].PREVMEMBER
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
30/37
Relative Calculations
Change since previous year
[Date].[Year].CURRENTMEMBER- [Date].[Year].PREVMEMBER
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
31/37
Hierarchies
Year
Month
Date
Product Type
Product Group
Product
Product Version
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
32/37
Parent Child Hierarchies
Top Dog
Manager
Employee
Employee
Employee
Employee
Employee
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
33/37
Dimension Navigation
DESCENDANTS
ANCESTORS
PARENT
CHILDREN
SIBLINGS
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
34/37
Demo Dimension Navigation
Dimension Navigation
DESCENDANTS
ANCESTORS
PARENT
CHILDREN
SIBLINGS
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
35/37
Visualising Queries
Very different to SQL
Think in blocks
E.g. All data EXCEPT for xxx
Run two queries and subtract them
minus
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
36/37
Think in MDX, not SQL
Get your head around the lingo
Member, Set, Tuple
Dimension / Measuregroup
Keep it simple
Use MDX for what its good for
MDX 101 - Summary
7/27/2019 SQL Sat Cambridge - MDX 101 - 20130928
37/37
MDX 101 Questions?.....
www.MDXpert.com
MDX Studio
www.PurpleFrogSystems.com [email protected]
www.PurpleFrogSystems.com/blog @PurpleFrogSys
http://www.mdxpert.com/http://www.purplefrogsystems.com/http://www.purplefrogsystems.com/bloghttp://www.purplefrogsystems.com/bloghttp://www.purplefrogsystems.com/http://www.mdxpert.com/