2. Introduction
◦ What is MDX
◦ Where MDX is required
Syntax and examples on MDX
Basics of MDX
Axis
Member Reference
Tuple
Partial Tuple
Sets
Calculated Members
Calculated Sets
Functions
Different reporting scenarios
3. MDX is a language used for querying and
manipulating data stored in OLAP Cubes (or say
multi-dimensional databases)
Concept is same as “SQL is a querying language”.
◦ SQL Relational Database
◦ MDX Multidimensional Database
MDX return multidimensional cell-sets that contain
the cube's data
4.
5. OLAP Cube Result (multidimensional
Cube-Sets)
MDX
Reporting Services
(SSRS, SAP TM1, Oracle Essbase,
Microstrategy, Tableau, Cognos etc.)
6. Syntax:
[ WITH <SELECT WITH clause> [ , <SELECT WITH clause>
... ] ]
SELECT [ * | ( <SELECT query axis clause>
[ , <SELECT query axis clause> ... ] ) ]
FROM <SELECT subcube clause>
[ <SELECT slicer axis clause> ]
[ <SELECT cell property list clause> ]
Simplest Syntax:
SELECT {set} ON AXIS(0)
, {set} ON AXIS(1)
FROM [Cube]
WHERE <<data is sliced by some coordinates>>
7. Before getting into details, you should be familiar with basics of Cube
terminology. This include Cube, Measures, Attribute Hierarchy,
Members, Level etc.
For revision please refer the link below:
http://bistuffwithdigven.wordpress.com/2012/10/10/cube-browsing/
8. a. Axis
b. Member Reference
c. Tuple
d. Partial Tuple
e. Sets
f. Calculated Members
g. Calculated Sets
9. Axes in MDX defines representation plane for data of result
set. Sometimes we put one dimension representing one axis.
For e.g. in 3-D space x,y,z are three axes (figure below)
In SELECT statement we specify what data on which axes of
result-set, is required
SELECT statement support 128 axes (i.e. 0 to 127)
Important axes in MDX are listed below (most used are 0 and
1):
Formal Name Short Name Alias
Axis(0) 0 COLUMNS
Axis(1) 1 ROWS
Axis(2) 2 PAGES
Axis(3) 3 SECTIONS
Axis(4) 4 CHAPTERS
10. Fully qualified name for each member in Cube
Multiple ways to give member reference:
[Dimension].[Attribute Hierarchy].[Attribute].[Member]
Without user hierarchy (Attribute Hierarchy is Attribute itself)
E.g.
◦ [Time].[Year].[Year].[2001]
◦ [Time].[Year].[Year].&[2001]
◦ [Time].[Year].[Year].&[1]
With user hierarchy
E.g.
◦ [Time].[Fiscal].[Year].[2001]
◦ [Time].[Calendar].[Year].&[2001]
◦ [Time].[Fiscal].[Year].&[1]
We need not Attribute name sometimes
E.g.
◦ [Time].[Year].[2001]
◦ [Time].[Calendar].[Year].[2001]
11. Ordered list of members from each dimensions of cube
Represent a point in the Cube space
A cell can be representation of a tuple
For e.g.
◦ In 3-D space (x1, y1, z1) is a tuple
◦ In a cube with 3 dimensions (2 dimensions and 1 for measures)
([Time].[Year].[Year].[2001], [Product].[Category].[Category].[Bikes], [Measures].[Sales Amount]) is a tuple
• In 3-D space, a tuple represent list of one member from
each axis. So an ordered members list says (x1, y1, z1) .
<In Red>
• In Cube a tuple is ordered list of member from each
dimension (more specifically each attribute of cube). In
this example we believe there are 2 Dimension only and 1
member from Measures Dimension is necessary. <In Blue>
12. Part of the tuple with less member reference, where rest of
the member reference are taken care with Analysis Services to
understand
That is, no need to list for all the members from each
dimension
Default member from dimension is used in place of Omitted
members
For e.g.
◦ In 3-D space, if we want to omit an axis tuple will be (0, y1, z1) i.e. with
zero
◦ In Cube space, if we omit Time dimension tuple will be
([Product].[Category].[Category].[Bikes], [Measures].[Sales Amount])
13. Ordered collection of tuples with the same
dimensionality, or hierarchality
E.g.
Sets with tuple having single member:
{[Time].[Year].[2001], [Time].[Year].[2007], [Time].[Year].[2009]}
Sets with tuple having multiple members:
{ (Time.[Year].[Year].[2001], [Product].[Category].[Category].[Bikes]),
(Time.[Year].[Year].[2002], [Product].[Category].[Category].[Clothing]) }
Sets with hierarchy involved:
{ (Time.[Fiscal].[Year].[2001], [Product].[Category].[Category].[Bikes]),
(Time.[Fiscal].[Year].[2002], [Product].[Category].[Category].[Clothing]) }
14. MDX provide way to create and query calculated members in
result set
Use WITH MEMBER clause before SELECT statement
Create a member in any dimensional attribute and Measures
dimension as well.
E.g. Dimensional Member:
WITH MEMBER [Product].[Category].[Popular] AS
[Product].[Category].[Category].[Bikes]+[Product].[Category].[Category].[Clothing
]
E.g. Measures member (new calculated measure):
WITH
MEMBER [Total Sales] AS
([Measures].[Reseller Sales Amount]+ [Measures].[Internet Sales Amount])
15. Same as Named Sets in Cube, we can create Calculated Sets in
MDX while querying
Sets are always collection of Tuples, so is a calculated set
Use WITH SET clause before SELECT statement
E.g. Calculated set for two members of Product Category:
WITH SET [Best Products] AS
{[Product].[Category].[Category].[Bikes],[Product].[Category].[Cat
egory].[Clothing]}
16. About 12-13 categories and more than 50
Functions
Functions eases the calculations and provide
desired results
Need to understand function with examples and
their uses
Broad categories are :
◦ Set Functions
◦ Navigation Functions
◦ Metadata Functions
◦ Time Functions
◦ String Functions
◦ UI Functions
17. Different reporting requirements needs different MDX
query manipulation
For example:
◦ We list all or selected members of one attribute to fill filter values of report
◦ We CROSSJOIN different attributes to get multiple columns or fields
required in report
◦ We use NON EMPTY to filter unnecessary rows from results
◦ We use STRTOSET, STRTOMEMBER to manipulate string as cube members
◦ We create calculated members and sets when desired fields are not
available in cube
◦ We use SUBCUBE functions and queries in MDX to avoid unwanted totals
There are many different scenarios coming across reporting needs.
But I am sure little hands on experience with MDX, can help you
find solution for all. That’s the beauty of MDX, its flexible and vast.
18. Please add all your queries and doubt here or
my blog:
http://bistuffwithdigven.wordpress.com/
For further details on functions and MDX please
comment on the blog posts.