You are on page 1of 29

MDX Multidimensional Expressions

Microsofts proposal for a multidimensional query and presentation language for OLE DB for OLAP
Robert Fenk March 11, 1999

Page 1

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Contents

MDX Overview
Data Cube MDX Syntax Data Set

MDX and Range Queries MDX Summary Implementing MDX Processing of two Example Queries
Page 2 Robert Fenk February 17, 2000, mdx-vortrag.tex

MDX Overview

MDX query

Data Set Data Cube

Page 3

Robert Fenk

February 17, 2000, mdx-vortrag.tex

MDX Data Cube


The MDX view of a multidimensional data cube: Dimension: a set of elements of the same type Member: elements of a dimension Hierarchy: groups members of a dimension MemberProperties: additional information

Page 4

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Example MDX Data Cube


4 Dimensions:

Salesperson, Time, Measures, Product


. . . , Netz, . . . , Venkatrao, . . . ..., 1998, Qtr1 1998, Jan 1998,

Salespersondim: Time dim: Measuresdim: Product dim:


MemberProps of

1/1/1998, . . . , 1999, . . . Sales, Turnover, . . . . . . , TV, ColorTV, . . . Name, Phone, . . .

Salespersondim:

Page 5

Robert Fenk

February 17, 2000, mdx-vortrag.tex

HierarchySchemata over the Time dimension


Dimension:Time Hierarchy: Quarters Level: All Level: Year Level: Quarter Level: Month Level: Day
A dimension member contained in different hierarchies A dimension member only contained in one hierarchy
Page 6 Robert Fenk February 17, 2000, mdx-vortrag.tex

Hierarchy: Weeks Level: All Level: Year Level: Weeks Level: Days

Example Hierarchy over the Time dimension


Dimension:Time Hierarchy: Quarters Level: All
All

Level: Year

...

1985

...
1998.Qtr1

1998

Level: Quarter
1998.Qtr2 1998.Qtr3 1998.Qtr4 Level: Month
1998.Qtr1.Jan 1998.Qtr1.Feb 1998.Qtr1.Mar 1998.Qtr4.Oct 1998.Qtr4.Nov 1998.Qtr4.Dec

Level: Day
1998.Qtr1.Jan.1 1998.Qtr1.Jan.31 1998.Qtr1.Dec.1 1998.Qtr1.Dec.31

Page 7

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Example Fact Table according to ROLAP


dimensions / key attributes
Salesperson Venkatrao Netz ... Time 1998 1998 ... Product TV TV ... Cost 50000 56789 ...

measures
Sales 10023 90023 ... Turnover 190000 100000 ...

Page 8

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Example Fact Table for an MDX Data Cube


dimensions / key attributes
Salesperson Venkatrao Venkatrao Venkatrao Netz Netz Netz ...
Page 9

one datacell
Value 50000 10023 190000 56789 90023 100000 ...
February 17, 2000, mdx-vortrag.tex

Time 1998 1998 1998 1998 1998 1998 ...

Product TV TV TV TV TV TV ...

Measures Cost Sales Turnover Cost Sales Turnover ...

Robert Fenk

MDX Rowsets storing meta data


CUBE Rowset
CATALOG_NAME SCHEMA_NAME CUBE_NAME CUBE_TYPE CUBE_GUID CREATED_ON LAST_SCHEMA_UPDATE SCHEMA_UPDATED_BY LAST_DATA_UPDATE DATA_UPDATED_BY DESCRIPTION

DIMENSIONS Rowset
CATALOG_NAME SCHEMA_NAME CUBE_NAME DIMENSION_NAME DIMENSION_UNIQUE_NAME DIMENSION_GUID DIMENSION_CAPTION DIMENSION_ORDINAL DIMENSION_TYPE DIMENSION_CARDINALITY DEFAULT_HIERARCHY DESCRIPTION

HIERACHIES Rowset
CATALOG_NAME SCHEMA_NAME CUBE_NAME DIMENSION_UNIQUE_NAME HIERARCHY_NAME HIERARCHY_UNIQUE_NAME HIERACHY_GUID HIERACHY_CAPTION DIMENSION_NAME HIERACHY_CARINALITY DEFAULT_MEMBER ALL_MEMBER DESCRIPTION

LEVELS Rowset
CATALOG_NAME SCHEMA_NAME CUBE_NAME DIMENSION_UNIQUE_NAME HIERARCHY_NAME HIERARCHY_UNIQUE_NAME LEVEL_NAME LEVEL_UNIQUE_NAME LEVEL_GUID LEVEL_CAPTION LEVEL_NUMBER LEVEL_CARDINALITY LEVEL_TYPE DESCRIPTION

MEASURES Rowset
CATALOG_NAME SCHEMA_NAME CUBE_NAME MEASURE_NAME MEASURE_UNIQUE_NAME MEASURE_CAPTION MEASURE_GUID MEASURE_AGGREGATOR DATA_TYPE NUMERIC_PRECISION NUMERIC_SCALE NUMERIC_UNITS DESCRIPTION

MEMBERS Rowset
CATALOG_NAME SCHEMA_NAME CUBE_NAME DIMENSION_UNIQUE_NAME HIERACHY_UNIQUE_NAME LEVEL_UNIQUE_NAME LEVEL_NUMBER MEMBER_ORDINAL MEMBER_NAME MEMBER_UNIQUE_NAME MEMBER_TYPE MEMBER_GUID MEMBER_CAPTION CHILDREN_CARDINALITY PARENT_LEVEL PARENT_UNIQUE_NAME PARENT_COUNT DESCRIPTION

PROPERTIES Rowset
CATALOG_NAME SCHEMA_NAME CUBE_NAME DIMENSION_UNIQUE_NAME HIERACHY_UNIQUE_NAME LEVEL_UNIQUE_NAME MEMBER_UNIQUE_NAME PROPERTY_TYPE PROPERTY_NAME PROPERTY_CAPTION DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DESCRIPTION

Page 10

Robert Fenk

February 17, 2000, mdx-vortrag.tex

MDX Syntax

[WITH

<formula_spec>] [, <axis_spec>, ...] [, <cube_spec>, ...] [cell_properties]

SELECT <axis_spec> FROM WHERE <cube_spec> <slicer_spec>

Page 11

Robert Fenk

February 17, 2000, mdx-vortrag.tex

MDX Syntax Description

WITH clause: creation of a new dimension member, which lives


in the context of the expression. e.g.:
WITH MEMBER Measures.[% Change from Last Years Sales] AS Sales / (Sales, Year.PREVMEMBER)

axis spec: maps dimensions to axes and gives restrictions. e.g.: 1998, 1999 ON COLUMNS cube spec: determines the data cube (usually a single data
cube)

slicer spec: restricts to dimensions not given in the axis spec (meaning of the cell contents)
Page 12 Robert Fenk February 17, 2000, mdx-vortrag.tex

MDXQuery Example

SELECT CROSSJOIN({Venkatrao, Netz}, {USA_North.CHILDREN, USA_South, Japan}) ON COLUMNS {Qtr1.CHILDREN, Qtr2, Qtr3, Qtr4.CHILDREN} ON ROWS FROM SalesCube WHERE (Sales, [1998], Products.All)

Page 13

Robert Fenk

February 17, 2000, mdx-vortrag.tex

MDX Data Set


The result of an MDXquery is called a data set. Dataset: a multidimensional cube / a set of Excel tables Axis: dimensions are mapped to axes Coordinate: elements of an axis Cell: element of the dataset specied by its axiscoordinates CellProperties: additional information

Page 14

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Example Data Set


Sum of all product sales for 1998:
Venkatrao USA USA North USA South Boston Jan Qtr1 Feb Mar Qtr2 Qtr3 Oct Nov Qtr4 Dec

Netz USA Japan Seattle


USA North USA South Boston


Japan Seattle

Page 15

Robert Fenk

February 17, 2000, mdx-vortrag.tex

MDX Summary

Data Cube: contains also aggregated measures


contains the measures (a single value) the type of the measure is given by the Measuredimension

Restriction: given by sets of members


sets of members are ordered ( data set)

axis spec and slicer spec

Projection:
members given in the axis

spec are mapped to axes

the order of the members denes the order of the coordinates


Page 16 Robert Fenk February 17, 2000, mdx-vortrag.tex

Restrictions resulting in intervals

member : member

(range)

dimension .MEMBERS hierarchy .MEMBERS level .MEMBERS member .CHILDREN level )

DESCENDANTS( member ,

Page 17

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Examples Restrictions resulting in a Range Queries


Restriction: Huber, 1998, Sales, TV MDX: UBTree: a point query resulting in a single measure. two ranges (Time and Product dimension), + aggregation Restriction: Huber, 1998.CHILDREN, Sales, TV Restriction: Huber:Maier, 1998.CHILDREN, Sales, TV.MEMBERS

Page 18

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Implementing MDX
1. Get an MDXParser 2. Map the data cube in a useful way to a DBMS e.g. a star schema of a RDBMS or a UBTree 3. Transform the MDXs to the querylanguage of the used DBMS e.g. MDX SQLs

4. Build up a data set with the results of the DBMSquery e.g. aggregations, reordering, folding 5. Provide the data set to the application

Page 19

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Implementing a MDX Data Cube (SalesCubeRelation)


create a fact table with one column per hierarchy level of each dimension
Salesperson Venkatrao Venkatrao Venkatrao Venkatrao Venkatrao Venkatrao Netz Netz Netz Netz Netz Netz Year 1998 1998 1998 1999 1999 1999 1998 1998 1998 1999 1999 1999 Month Jan Feb Mar Jan Feb Mar Jan Feb Mar Jan Feb Mar Day 1 2 3 1 2 3 1 2 3 1 2 3 Product TV TV TV TV TV TV TV TV TV TV TV TV Sales 4 16 68 71 41 30 86 68 89 40 32 82

Page 20

Robert Fenk

February 17, 2000, mdx-vortrag.tex

Implementing MDX Queries


Query Transformation:

extract the restrictions on dimensions given in the axis spec and slicer spec determine by the slicer spec over which dimensions we
aggregate and get the aggregation type from the meta date Query Execution:

recognize ranges in the restrictions on the dimensions execute the transformed query
Transformation of the Result Relation to a Data Set:

reordering of the result relation according to the axis spec folding of the result relation according to the axis spec
Page 21 Robert Fenk February 17, 2000, mdx-vortrag.tex

COGNOS like MDX Example (1/4)

SELECT { Salesperson.All.Venkatrao, Salesperson.All.Netz } ON AXIS(0) { Time.All.1998, Time.All.1999 } ON AXIS(1) FROM SalesCube WHERE { Product.All.TV, Measures.All.Sales }

Page 22

Robert Fenk

February 17, 2000, mdx-vortrag.tex

COGNOS like MDX Example (2/4)


The dimensions are restricted to: Salesperson: Time: Product: Measures: Aggregation is done over: Venkatrao, Netz 1998, 1999 TV Sales

Salepersondimension Year dimension

Page 23

Robert Fenk

February 17, 2000, mdx-vortrag.tex

COGNOS like MDX Example (3/4)


fold where

SalesCubeRelation Salesperson Venkatrao Netz Year

TV Measures Sales
Product

Sales
Page 24

Salesperson Year

Robert Fenk

February 17, 2000, mdx-vortrag.tex

COGNOS like MDX Example (4/4)


Result Relation:
Salesperson Venkatrao Venkatrao Netz Netz Year 1998 1999 1998 1999 Product TV TV TV TV Sales 88 142 243 154

Data Set: By folding the result relation according to the axis specication we get the following data set: Sum of the TV Sales
Venkatrao 1998 1999 88 142 Netz 243 154

Page 25

Robert Fenk

February 17, 2000, mdx-vortrag.tex

More general Example (1/4)

SELECT CROSSJOIN({Venkatrao, Netz}, {1998.Jan, 1998.Feb, 1998.Mar, 1998}) ON AXIS(0) {TV, Computer, Product.ALL} ON AXIS(1) FROM SalesCube WHERE {Sales}

Page 26

Robert Fenk

February 17, 2000, mdx-vortrag.tex

More general Example (2/4)


fold


Venkatrao Netz Product TV Computer Sales

Salesperson Year

Measures

Salesperson Year Month Product Salesperson Year Product Salesperson Year Month Salesperson Year

Month

Jan, Feb, Mar Year Month


Robert Fenk

Sales

ALL

February 17, 2000, mdx-vortrag.tex

Page 27

More general Example (3/4)


Result Relation:
Salesperson Netz Netz Netz ... Netz ... Netz ... Netz ... Venkatrao ... Venkatrao Venkatrao Venkatrao ... Venkatrao ... Venkatrao Year 1998 1998 1998 ... 1998 ... 1998 ... 1998 ... 1998 ... 1998 1998 1998 ... 1998 ... 1998 Month Jan Feb Mar ... ALL ... ALL ... ALL ... ALL ... Jan Feb Mar ... ALL ... ALL Product TV TV TV ... TV ... Computer ... ALL ... TV ... Computer Computer Computer ... Computer ... ALL Sales ... ... ... ... 243 ... 417 ... 660 ... 150 ... ... ... ... ... 350 ... 500

Page 28

Robert Fenk

February 17, 2000, mdx-vortrag.tex

More general Example (4/4)


Data Set:
Venkatrao 1998 Feb Mar ... ... ... ... ... ... Netz 1998 Feb Mar ... ... ... ... ... ...

TV Computer ALL

Jan ... ... ...

1998 150 350 500

Jan ... ... ...

1998 243 417 660

Page 29

Robert Fenk

February 17, 2000, mdx-vortrag.tex

You might also like