29
SSAS MDX Language Presented By Vinod – Architect – Crestron Electronics

Ssas mdx language

Embed Size (px)

Citation preview

Page 1: Ssas mdx language

SSAS MDX LanguagePresented By Vinod – Architect – Crestron Electronics

Page 2: Ssas mdx language

Differences between SQL Server Vs SSAS

• SQL Server Database Engine Services• Data storage and retrieval is based on set theory.

• Analysis Services• Based on the concept of an n-dimensional space

• SQL language• Assemble sets of data

• MDX Language• Assemble tuples identifying points of data within an n-dimensional space

Page 3: Ssas mdx language

SSAS MDX Overview

• MDX Language

• Tuples

• Cells

• Sets

Page 4: Ssas mdx language

MDX Language

Page 5: Ssas mdx language

MDX Vs SQL

• MDX and SQL statements are completely superficial

• Do not attempt to learn MDX in the context of SQL

Page 6: Ssas mdx language

MDX Select

• SELECT FROM [Adventure Works]

• SELECT FROM [Adventure Works] WHERE [Date].[Calendar Year].&[2004]

Page 7: Ssas mdx language

MDX Select

• SELECT [Measures].[Reseller Sales Amount] ON COLUMNS

FROM [Adventure Works]

WHERE [Date].[Calendar Year].&[2004]

Page 8: Ssas mdx language

MDX Select

• SELECT [Measures].[Reseller Sales Amount] ON COLUMNS,

[Product].[Category].MEMBERS ON ROWS

FROM [Step-by-Step]

WHERE [Date].[Calendar Year].&[2004]

Page 9: Ssas mdx language

MDX Select without Where

Page 10: Ssas mdx language

Tuples

Page 11: Ssas mdx language

Understanding Tuples• Within a cube space, data are made accessible through cells, each

uniquely identified by a tuple

• N-dimensional Space• 2-Dimensional coordinate system, (x, y) => (3, 4)

Page 12: Ssas mdx language

Understanding Tuples

• N-dimensional Space• 3-Dimensional coordinate system, (x, y, z) => (3, 4, 2)

Page 13: Ssas mdx language

Understanding Tuples

• N-dimensional Space• Four-dimensional space

• Can no longer be easily visualized• Points within this space can be located using a quadruple-coordinate system of the form

(a1, a2, a3, a4)

• Five-dimensional space => quintuple-coordinate system• (a1, a2, a3, a4, a5)

• Six-dimensional space => sextuple-coordinate system• (a1, a2, a3, a4, a5, a6)

• n-dimensional spaces• Spaces have n number of axes• coordinate systems of the form (a1, a2,. . .,an) => Called TUPLE

Page 14: Ssas mdx language

Accessing Data with Tuples

• SELECT FROM [Adventure Works]

WHERE (

[Date].[Calendar Year].[All Periods],

[Date].[Fiscal Year].[All Periods],

[Product].[Category].[Bikes],

[Product].[Subcategory].[Mountain Bikes],

[Measures].[Measures].[Reseller Sales Amount]

) => Tuple

Page 15: Ssas mdx language

Understanding Cells

• Points within cube spaces are occupied by cells

• Cells are objects and as such have a number of properties

• The default properties returned are VALUE and FORMATTED_VALUE.

• The VALUE property contains an aggregated measure valueSELECT

FROM [Adventure Works]

WHERE (

[Date].[Calendar Year].[All Periods],

[Date].[Fiscal Year].[All Periods],

[Product].[Category].[Bikes],

[Product].[Subcategory].[Mountain Bikes],

[Measures].[Measures].[Reseller Sales Amount]

)

aggregated value for the Reseller Sales Amount measure limited to => • Calendar Year,• Fiscal Year attribute-hierarchies’ All Periods members, • the Category attribute-hierarchy’s Bikes member, • the Subcategory attribute-hierarchy’s Mountain Bikes

member:

Page 16: Ssas mdx language

Understanding Cells

SELECTFROM [Chapter 3 Cube]WHERE (

[Product].[Subcategory].[Mountain Bikes],[Date].[Calendar Year].[All Periods],[Date].[Fiscal Year].[All Periods],[Product].[Category].[Bikes],[Measures].[Measures].[Reseller Sales Amount])

CELL PROPERTIES FORMATTED_VALUE, FORMAT_STRING

Page 17: Ssas mdx language

Partial Tuples

SELECT

FROM [Chapter 3 Cube]

WHERE (

[Date].[Calendar Year].[All Periods],

[Date].[Fiscal Year].[All Periods],

[Product].[Category].[Bikes],

[Product].[Subcategory].[Mountain Bikes],

[Measures].[Measures].[Reseller Sales Amount]

)

Page 18: Ssas mdx language

Sets

Page 19: Ssas mdx language

Set Basics

Using collections of tuples, known as sets, to retrieve multiple cells

{

([Product].[Category].[Accessories]),

([Product].[Category].[Bikes]),

([Product].[Category].[Clothing]),

([Product].[Category].[Components])

}

SET

Page 20: Ssas mdx language

Set Constraints

• Shared hierarchality

{

([Product].[Category].[Accessories]),

([Product].[Category].[Bikes]),

([Product].[Category].[Clothing]),

([Product].[Category].[Components])

}

SELECT{

([Date].[Calendar].[CY 2002], [Geography].[Country].[United States]),

([Date].[Calendar].[CY 2003], [Geography].[Country].[United States]),

([Date].[Calendar].[CY 2004], [Geography].[Country].[United States])

} ON COLUMNS,{

([Product].[Category].[Accessories]),([Product].[Category].[Bikes]),([Product].[Category].[Clothing]),([Product].[Category].[Components]),([Product].[Subcategory].[Mountain Bikes])} ON ROWS

FROM [Step-by-Step]

Incorrect Hierarchy in the Set

Page 21: Ssas mdx language

Set Results

SELECT

{

([Date].[Calendar].[CY 2002], [Geography].[Country].[United States]),

([Date].[Calendar].[CY 2003], [Geography].[Country].[United States]),

([Date].[Calendar].[CY 2004], [Geography].[Country].[United States])

} ON COLUMNS,

{

([Product].[Category].[Accessories]),

([Product].[Category].[Bikes]),

([Product].[Category].[Clothing]),

([Product].[Category].[Components])

} ON ROWS

FROM [Step-by-Step]

Page 22: Ssas mdx language

Set ConstraintsSELECT

{([Geography].[Country].[United States],

[Date].[Calendar].[CY 2002]),([Date].[Calendar].[CY 2003],

[Geography].[Country].[United States]),([Date].[Calendar].[CY 2004],

[Geography].[Country].[United States])} ON COLUMNS,

{([Product].[Product Categories].[Accessories]),([Product].[Product Categories].[Bikes]),([Product].[Product Categories].[Clothing]),([Product].[Product Categories].[Components]),([Product].[Product Categories].[Mountain Bikes])} ON ROWS

FROM [Step-by-Step]

SELECT{

([Geography].[Country].[United States], [Date].[Calendar].[CY 2002]),

([Geography].[Country].[United States], [Date].[Calendar].[CY 2003]),

([Geography].[Country].[United States], [Date].[Calendar].[CY 2004])

} ON COLUMNS,{

([Product].[Product Categories].[Accessories]),([Product].[Product Categories].[Bikes]),([Product].[Product Categories].[Clothing]),([Product].[Product Categories].[Components]),([Product].[Product Categories].[Mountain Bikes])} ON ROWS

FROM [Step-by-Step]

Incorrect Correct

Page 23: Ssas mdx language

Select statement Axis

• The SELECT statement supports up to 128 axes with each axis formally named Axis(n) where n is the number 0 through 127

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

Page 24: Ssas mdx language

Sets with Functions

• The Members Function

[Dimension].[Hierarchy].Members

[Dimension].[Hierarchy].[Level].Members

SELECT{

([Date].[Calendar].[CY 2002]),([Date].[Calendar].[CY 2003]),([Date].[Calendar].[CY 2004])} ON COLUMNS,

{([Product].[Category].[Accessories]),([Product].[Category].[Bikes]),([Product].[Category].[Clothing]),([Product].[Category].[Components])} ON ROWS

FROM [Step-by-Step]WHERE ([Geography].[Country].[United States])

SELECT{

([Date].[Calendar].[CY 2002]),([Date].[Calendar].[CY 2003]),([Date].[Calendar].[CY 2004])} ON COLUMNS,

{[Product].[Category].[Category].Members} ON ROWSFROM [Step-by-Step]WHERE ([Geography].[Country].[United States])

Page 25: Ssas mdx language

The Crossjoin Function

Crossjoin( {Set1}, {Set2} [, . . . {Setn} )

SELECT

{

([Date].[Calendar].[CY 2002]),

([Date].[Calendar].[CY 2003]),

([Date].[Calendar].[CY 2004])

} ON COLUMNS,

Crossjoin(

{[Product].[Category].[Category].Members},

{

([Measures].[Reseller Sales Amount]),

([Measures].[Reseller Order Quantity])

}

) ON ROWS

FROM [Step-by-Step]

WHERE ([Geography].[Country].[United States])

Page 26: Ssas mdx language

The Crossjoin Function

SELECT

{

([Date].[Calendar].[CY 2002]),

([Date].[Calendar].[CY 2003]),

([Date].[Calendar].[CY 2004])

} ON COLUMNS,

{[Product].[Category].[Category].Members} *

{

([Measures].[Reseller Sales Amount]),

([Measures].[Reseller Order Quantity])

} ON ROWS

FROM [Step-by-Step]

WHERE ([Geography].[Country].[United States])

Page 27: Ssas mdx language

Calculated Members

WITH

MEMBER [Product].[Category].[All Products].[X] AS

1+1

SELECT

{

([Date].[Calendar Year].[CY 2003]),

([Date].[Calendar Year].[CY 2004])

} ON COLUMNS,

{

([Product].[Category].[Accessories]) ,

([Product].[Category].[Bikes]),

([Product].[Category].[Clothing]),

([Product].[Category].[Components]),

([Product].[Category].[X])

} ON ROWS

FROM [Step-by-Step]

Page 28: Ssas mdx language

NON EMPTY function

SELECT

{[Measures].[Reseller Sales Amount]} ON COLUMNS,

NON EMPTY {[Date].[Month].[May 2002]} *

{[Employee].[Employee].Members} ON ROWS

FROM [Step-by-Step]

Page 29: Ssas mdx language

Thank You