MDX (Multidimensional Expressions) is a query language for OLAP databases, much like SQL is a query language for relational databases. Tutorial presents introduction to MDX. Watch video lesson, visit http://www.learn-with-video-tutorials.com/mdx-video-tutorial
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
MDX introduction
1. MDX tutorial
MDX (Multidimensional Expressions) is a query language for OLAP databases, much like
SQL is a query language for relational databases. It is also a calculation language, with
syntax similar to spreadsheet formulas. MDX is used to interact with data in Microsoft SQL
Server Analysis Services cubes. It is a versatile and powerful language but one that
requires you to approach data in a whole new way.
With relational databases, the SQL language is used to assemble sets of data. With
Analysis Services, the MDX language is used to assemble tuples identifying points of data
within an n-dimensional space.
The Data Warehouse layer is the heart of the business intelligence environment. In this
layer, data from across the enterprise is presented as a unifi ed whole and in a manner
focused more on business processes and less on the source systems from which the data
originates. The dimensional model has been widely embraced as the data model of choice
within the Data Warehouse layer. Within the dimensional model, business processes and
events are presented as facts.
Measurements associated with these facts, known as fact measures, provide a means of
evaluating the represented business process or event. Facts and their fact measures are
of little value without their associated descriptive details. These details, referred to as
attributes, provide the means by which facts are sliced (filtered) and diced (grouped).
Attributes are organized in dimensions with closely related attributes residing in the same
dimension.
Within Analysis Services, the dimensional model is presented as an object referred to as a
cube. Within the cube, facts are translated into measure groups. Measure groups contain
one or more measures, corresponding to fact measures in the dimensional model.
Through the cube, dimensions are presented as cube dimensions. Relationships between
the measure groups and cube dimensions are maintained as metadata within the cube
and are automatically employed as users interact with it.
Within a cube dimension, attributes are presented as either attribute-hierarchies or
properties. An attribute is presented as an attribute-hierarchy when the attribute is
intended to be used to slice and dice the data. When an attribute is intended to provide
supplemental information or to be used for simply filtering other attributes, it is best
employed as a property.
Relationships between attributes within a dimension are explicitly defined. As with the
relationships between measure groups and cube dimensions, this information is
maintained within the multidimensional database and automatically employed as users
interact with the cube
Here is the sample cube schema.
http://www.learn-with-video-tutorials.com/mdx-video-tutorial
2. MDX tutorial
SELECT
[Measures].[Amount] ON COLUMNS
FROM
[Car Transactions]
Number of cars sold.
The SELECT clause defines which dimension members to include on each exis of the
reprot and the FROM clause names the cube that is being queried. The query contains no
dimension members.
To display the number of transactions we should execute the following query.
SELECT
[Measures].[Transactions Facts Table Count] ON COLUMNS
FROM
[Car Transactions]
If we create a query that has only one axis, it must be the column axis.
http://www.learn-with-video-tutorials.com/mdx-video-tutorial
3. MDX tutorial
SELECT
[Measures].[Price] ON COLUMNS,
[Cars].[Category].MEMBERS ON ROWS
FROM
[Car Transactions]
Total price of cars sold by category
The MEMBERS() function returns the set of members in a dimension, level or hierarchy.
The query returns the total sales price in each category.
SELECT
[Cars].[Category].MEMBERS ON ROWS,
[Measures].[Price] ON COLUMNS
FROM
[Car Transactions]
If we create two axes, one must be the column axis and one must be the row axis,
although it doesn't matter in which order they appear within the query.
SELECT
Cars.Category.MEMBERS ON ROWS,
Measures.Price ON COLUMNS
FROM
[Car Transactions]
The square brackets around a particular object identifier are optional as long as the object
identifier is not one of reserver words and does not otherwise contain any characters
other than letters, numbers or underscores.
SELECT
Cars.Category.MEMBERS ON ROWS,
Measures.Price ON COLUMNS
http://www.learn-with-video-tutorials.com/mdx-video-tutorial
4. MDX tutorial
FROM
Car Transactions
Cube name contains a space, so it have to be enclosed by square brackets.
SELECT
[Cars].[Category].MEMBERS ON AXIS(0),
[Measures].[Price] ON AXIS(1)
FROM
[Car Transactions]
The terms COLUMNS and ROWS are simply aliases for the true names of the axes:
Axis(0) and Axis(1) respectively. Technically, an MDX query can have up to 128 axes, with
aliases for the first five: Columns, Rows, Pages, Sections and Chapters. This fact make it
clearer to understand why a single-axis report must have a COLUMNS axis (Axis(0)) but
not a ROW axis (Axis(1)). Although our query may be correct with three axes, SQL Server
Management Studio can only render bidimensional results.
SELECT
[Cars].[Category].MEMBERS ON COLUMNS,
[Cars].[Country].[Country] ON ROWS,
[Measures].[Price] ON PAGES
FROM
[Car Transactions]
If we want do display 3D results we need to find software that can present cube data more
elaborately.
SELECT
[Measures].[Price] ON COLUMNS,
NONEMPTY([Cars].[Category].MEMBERS) ON ROWS
FROM
[Car Transactions]
The NONEMPTY() function returns the tuples that are non-empty.
http://www.learn-with-video-tutorials.com/mdx-video-tutorial
5. MDX tutorial
SELECT
[Measures].MEMBERS ON COLUMNS,
NONEMPTY([Cars].[Category].MEMBERS) ON ROWS
FROM
[Car Transactions]
The MEMBERS() function can be used with measures dimension: returns only measures
defined directly on the cube - calculated members are not displayed.
SELECT
ADDCALCULATEDMEMBERS([Measures].MEMBERS) ON COLUMNS,
NONEMPTY([Cars].[Category].MEMBERS) ON ROWS
FROM
[Car Transactions]
The ADDCALCULATEDMEMBERS() function returns all measures, even calculated
members, from the measures dimension when the calculated members have not been
explicitly specified in the query.
SELECT
[Measures].ALLMEMBERS ON COLUMNS,
NONEMPTY([Cars].[Category].MEMBERS) ON ROWS
FROM
[Car Transactions]
The ALLMEMBERS() function returns a set that consists of all members of the supplied
level.
Watch video lesson, visit http://www.learn-with-video-tutorials.com/mdx-video-tutorial
http://www.learn-with-video-tutorials.com/mdx-video-tutorial