Date post: | 26-May-2017 |
Category: |
Documents |
Upload: | constantin-bostan |
View: | 230 times |
Download: | 0 times |
St. gr. TI-131M Bostan C.
Analytical overview of MDX queries. Examples of MDX queries for data
analysis.
Content
● Introduction● MDX Usage● Key concepts● MDX Structure● Examples of MDX usage for data analysis (Cube
slice, WITH statements, Build in functions, etc)
Introduction
The purpose of Multidimensional Expressions (MDX) is to make accessing data from multiple dimensions easier and more intuitive.
MDX was first introduced as part of the OLE DB for OLAP specification in 1997 by Microsoft
MDX Usage
Key Concepts
● Dimensions: Data cubes have more than two dimensions. Ex: route, source and time
● Levels: detalization level of a dimension. Ex time: 1st half and 2nd half of the year.
● Members: refers to the specific row and column of a dimension table
● Measures: A measure is a value from a fact table, and is also called a fact. Measures are generally numeric values
MDX Query Structure
MDX Query Structure
WITH this clause always precedes the SELECT statement and defines a member or set used within the SELECT.
WITH CACHE is optimizing the performance of the current query at the expense of creating a memory overhead
WITH <measure_name> AS <operation>
SELECT <measure_name>,
<other_statements>
FROM <tuple_or_set>
Cube Slice Example 1select
{[Product].[Product Categories].[Category],[Product].
[Product Categories]}
on columns
from
[Adventure Works]
where
[Customer].[Customer Geography].[Country].[Canada]
Cube Slice Example 2select
{[Product].[Product Categories].[Category],[Product].[Product Categories]}
on columns
from [Adventure Works] where
({[Customer].[Customer Geography].[Country].[Canada],
[Customer].[Customer Geography].[Country].[Australia]},
[Measures].[Internet Sales Amount])
WITH statement example
WITH member [measures].[internet profit] AS
'[measures].[internet sales amount]-[measures].[internet total product cost]'
SELECT {[measures].[internet profit],
[measures].[internet sales amount],
[measures].[internet total product cost]} ON COLUMNS,
{[product].[category].children} ON ROWS
FROM [adventure works]
Result of WITH statement example
MDX build in functionsFunction Description
IS Function Evaluates the equivalency of two objects
IsEmpty Checks whether the cell value is empty
IsGeneration Checks whether a particular member belongs to a specific level
Avg,Max,Min,Sum Basic numeric operations similar to simple SQL statements
FirstChild Returns the first child of a member.
MDX build in functions examples
WITH
MEMBER[cars].[all cars].[us] AS '
SUM( { [cars].[all cars].[chevy],
[cars].[all cars].[chrysler],
[cars].[all cars].[ford]
} ) '
SELECT
{ [cars].[all cars].us, [cars].[all cars].toyota } ON COLUMNS,
{ [date].members } ON ROWS
FROM mddbcars
MDX build in functions examplesIS EMPTY example:
WITH MEMBER MEASURES.ISEMPTYDEMO AS
IsEmpty([Measures].[Internet Sales Amount])
SELECT {[Measures].[Internet Sales Amount],MEASURES.ISEMPTYDEMO} ON 0,
[Date].[Fiscal].MEMBERS ON 1 FROM [Adventure Works]
ISGENERATION example:
SELECT FILTER({[product].[product categories].members}, ISGENERATION ([product].[product categories].CurrentMember, 2 )) ON ROWS, {[measures].[order count]} ON COLUMNS FROM [adventure works]
Conclusions● Older versions of systems that uses MDX can
have different syntax for build in functions in comparison with the new versions.
● By using MDX language various reports or useful information can be generated.
● Although SQL and MDX have similar keywords structure, MDX query was designed to retrieve multidimensional data structures and SQL was created to handle only two-dimensional tabular data