15
St. gr. TI-131M Bostan C. Analytical overview of MDX queries. Examples of MDX queries for data analysis.

Bostan C MDX

Embed Size (px)

Citation preview

Page 1: Bostan C MDX

St. gr. TI-131M Bostan C.

Analytical overview of MDX queries. Examples of MDX queries for data

analysis.

Page 2: Bostan C MDX

Content

● Introduction● MDX Usage● Key concepts● MDX Structure● Examples of MDX usage for data analysis (Cube

slice, WITH statements, Build in functions, etc)

Page 3: Bostan C MDX

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

Page 4: Bostan C MDX

MDX Usage

Page 5: Bostan C MDX

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

Page 6: Bostan C MDX

MDX Query Structure

Page 7: Bostan C MDX

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>

Page 8: Bostan C MDX

Cube Slice Example 1select

{[Product].[Product Categories].[Category],[Product].

[Product Categories]}

on columns

from

[Adventure Works]

where

[Customer].[Customer Geography].[Country].[Canada]

Page 9: Bostan C MDX

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])

Page 10: Bostan C MDX

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]

Page 11: Bostan C MDX

Result of WITH statement example

Page 12: Bostan C MDX

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.

Page 13: Bostan C MDX

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

Page 14: Bostan C MDX

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]

Page 15: Bostan C MDX

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