SSAS MDX Language
Presented By Vinod – Architect – Crestron Electronics
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
SSAS MDX Overview
• MDX Language
• Tuples
• Cells
• Sets
MDX Language
MDX Vs SQL
• MDX and SQL statements are completely superficial
• Do not attempt to learn MDX in the context of SQL
MDX Select
• SELECT FROM [Adventure Works]
• SELECT FROM [Adventure Works] WHERE [Date].[Calendar
Year].&[2004]
MDX Select
• SELECT [Measures].[Reseller Sales Amount] ON COLUMNS
FROM [Adventure Works]
WHERE [Date].[Calendar Year].&[2004]
MDX Select
• SELECT [Measures].[Reseller Sales Amount] ON COLUMNS,
[Product].[Category].MEMBERS ON ROWS
FROM [Step-by-Step]
WHERE [Date].[Calendar Year].&[2004]
MDX Select without Where
Tuples
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)
Understanding Tuples
• N-dimensional Space
• 3-Dimensional coordinate system, (x, y, z) => (3, 4, 2)
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
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
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 value
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]
)
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:
Understanding Cells
SELECT
FROM [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
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]
)
Sets
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
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
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]
Set Constraints
SELECT
{
([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
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
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 ROWS
FROM [Step-by-Step]
WHERE ([Geography].[Country].[United States])
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])
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])
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]
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]
Thank You

Ssas mdx language

  • 1.
    SSAS MDX Language PresentedBy Vinod – Architect – Crestron Electronics
  • 2.
    Differences between SQLServer 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
  • 3.
    SSAS MDX Overview •MDX Language • Tuples • Cells • Sets
  • 4.
  • 5.
    MDX Vs SQL •MDX and SQL statements are completely superficial • Do not attempt to learn MDX in the context of SQL
  • 6.
    MDX Select • SELECTFROM [Adventure Works] • SELECT FROM [Adventure Works] WHERE [Date].[Calendar Year].&[2004]
  • 7.
    MDX Select • SELECT[Measures].[Reseller Sales Amount] ON COLUMNS FROM [Adventure Works] WHERE [Date].[Calendar Year].&[2004]
  • 8.
    MDX Select • SELECT[Measures].[Reseller Sales Amount] ON COLUMNS, [Product].[Category].MEMBERS ON ROWS FROM [Step-by-Step] WHERE [Date].[Calendar Year].&[2004]
  • 9.
  • 10.
  • 11.
    Understanding Tuples • Withina 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)
  • 12.
    Understanding Tuples • N-dimensionalSpace • 3-Dimensional coordinate system, (x, y, z) => (3, 4, 2)
  • 13.
    Understanding Tuples • N-dimensionalSpace • 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
  • 14.
    Accessing Data withTuples • 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
  • 15.
    Understanding Cells • Pointswithin 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 value 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] ) 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:
  • 16.
    Understanding Cells SELECT FROM [Chapter3 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
  • 17.
    Partial Tuples SELECT FROM [Chapter3 Cube] WHERE ( [Date].[Calendar Year].[All Periods], [Date].[Fiscal Year].[All Periods], [Product].[Category].[Bikes], [Product].[Subcategory].[Mountain Bikes], [Measures].[Measures].[Reseller Sales Amount] )
  • 18.
  • 19.
    Set Basics Using collectionsof tuples, known as sets, to retrieve multiple cells { ([Product].[Category].[Accessories]), ([Product].[Category].[Bikes]), ([Product].[Category].[Clothing]), ([Product].[Category].[Components]) } SET
  • 20.
    Set Constraints • Sharedhierarchality { ([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
  • 21.
    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]
  • 22.
    Set Constraints SELECT { ([Geography].[Country].[United States], [Date].[Calendar].[CY2002]), ([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
  • 23.
    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
  • 24.
    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 ROWS FROM [Step-by-Step] WHERE ([Geography].[Country].[United States])
  • 25.
    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])
  • 26.
    The Crossjoin Function SELECT { ([Date].[Calendar].[CY2002]), ([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])
  • 27.
    Calculated Members WITH MEMBER [Product].[Category].[AllProducts].[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]
  • 28.
    NON EMPTY function SELECT {[Measures].[ResellerSales Amount]} ON COLUMNS, NON EMPTY {[Date].[Month].[May 2002]} * {[Employee].[Employee].Members} ON ROWS FROM [Step-by-Step]
  • 29.