MDX Overview Nived Varma
MDX Overview Nived Varma
Nived Varma
[email protected]
What Is MDX?
• MDX is Multi Dimensional EXpressions
• MDX is the syntax for querying an Analysis
Services database
• MDX is part of the OLE DB for OLAP spec
• MDX is the key for all advanced analytical
capabilities of Analysis Services
Comparison To SQL
SQL Construct OLAP construct
SELECT… SELECT… (MDX)
CREATE… DSO object model
DROP…
INSERT…
DELETE…
MDX Basics
• MDX allows easy navigation in the
multi dimensional space
• It “understands” the MD concepts of
cube, dimension, level, member
and cell
• It is used for
– Queries – full statements
(SELECT…FROM)
– Business modeling – defining
calculated members using MDX
Expressions – not a full statement
MDX Queries vs. MDX Expressions
• MDX Queries
– Full statements (SELECT…FROM)
– Usually generated by a query tools and
applications such as Excel
– MDX Sample App deals in queries
• MDX Expressions
– Partial MDX statements
– Define a calculated member, or a set, or
member properties, etc.
– Returns a single value (which may
be a set)
MDX Myth
“Only developers need to know MDX”
Fact: MDX is used everywhere:
Calculated members
Security settings
Actions
Calculated cells
MDX Constructs
• Members: an item in a hierarchy
– [John Doe]
– [2001]
– [2001].[Q1].[Jan]
• Tuple: an intersection of 2 or more members
– ([Product].[Drink].[Beverages], [Customers].[USA])
– ([Product].[Non-Consumable], [2001])
• Sets: a group of tuples or members
– {[John Doe], [Jane Doe]}
– { ( [Non-Consumable], USA ), ( Beverages, Mexico ) }
– [2001].Children
– TopCount(Store.[Store Name].
Members, 10, Sales)
Every Cell Has A Name...
Groceries
Appliances
Clothing
1997
1998
Time
1999
2000
2001
Measures
Every Cell Has A Name...
(Products.Clothing, Measures.Units, Time.[2000])
Groceries
Appliances
Clothing
1997
1998
Time
1999
2000
2001
Measures
Every Cell Has A Name...
(Products.Clothing, Measures.Units, Time.[2000])
(Products.Clothing, Measures.Sales, Time.[1999])
Groceries
Appliances
Clothing
1997
1998
Time
1999
2000
2001
Measures
Every Cell Has A Name...
(Products.Clothing, Measures.Units, Time.[2000])
(Products.Clothing, Measures.Sales, Time.[1999])
(Products.Groceries, Measures.Cost, Time.Year.[1997])
Groceries
Appliances
Clothing
1997
1998
Time
1999
2000
2001
Measures
The Current Cell: Currentmember
Clothing
?
2000
Sales
Naming Cells With Relative References...
(Products.Clothing, Measures.Sales, Time.[2000].PrevMember)
Clothing
?
2000
?
Sales
Naming Cells With Relative References...
Clothing
?
?
2000
?
Sales
Naming Cells With Relative References...
(Products.Clothing, Measures.Sales, Time.[2000].PrevMember)
(Products.Clothing, Measures.Sales, Time.[2000].NextMember)
(Products.Clothing, Measures.Sales.PrevMember, Time.[2000].Lag(3))
OR
Clothing
(Products.Clothing,
? Measures.Sales.PrevMember,
Time.[2000].Lead(-3))
?
2000
?
Sales
Calculated Members
• Calculated members add
significant power to Analysis cubes
Pre-define complex
business logic
Usually create
calculated
measures
Computed at run-
time
1. How Did Sales This Period Compare With Sales In The Previous
Period?
Year Qtr Mon Sales
2000 790
Q1 120
Jan 30
Feb 40
Mar 50
Q2 200
Apr 65
May 45
Jun 90
Q3 185
Jul 55
Aug 60
Sep 70
Q4 285
Oct 80
Nov 100
Dec 105
1. How Did Sales This Period Compare With Sales In The Previous
Period?
(Time.CurrentMember, Measures.CurrentMember) =
1. How Did Sales This Period Compare With Sales In The Previous
Period?
(Time.CurrentMember, Measures.CurrentMember) =
(Time.CurrentMember, Measures.Sales) -
1. How Did Sales This Period Compare With Sales In The Previous
Period?
(Time.CurrentMember, Measures.CurrentMember) =
(Time.CurrentMember, Measures.Sales)
-
(Time.CurrentMember.PrevMember, Measures.Sales)
Results For Question 1:
(Time.CurrentMember, Measures.Sales)-
(Time.CurrentMember.Lag(12), Measures.Sales)
2. How Did Sales In The Current Period Compare With Sales In The Same
Period Last Year?
Year Qtr Mon Sales Annual Delta
2000 790
Q1 120
Jan 30
Feb 40
Mar 50
2001 850
Q1 170
Jan 50 20
Feb 55
Mar 65
(Time.CurrentMember, Measures.Sales)-
(Time.CurrentMember,Lag(12), Measures.Sales)
(ParallelPeriod(Year,1,Time.CurrentMember),
Measures.Sales)
Results For Question 2:
Time.Jan,Measures.Sales +
Time.Feb,Measures.Sales +
Time.Mar,Measures.Sales ...
3. What Have Sales Been Since The Beginning Of The Year?
Time.Jan,Measures.Sales +
Time.Feb,Measures.Sales +
Time.Mar,Measures.Sales =
Sum(YTD(Time.CurrentMember), Sales)
Results For Question 3: