ASDAWREWFAD

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

A SQL Server Developer’s Guide to

MDX Basics
Shabnam Watson
Presentation Goal and Audience
 What will you learn?
 Basic concepts of a multidimensional SSAS cube from a
querying perspective.
 Write basic MDX queries to run from SSMS, SSRS, etc.

 Who is this for? Application Developers, BI Developers, QA


team.

 Requirements
 Understanding of basic dimensional modeling concepts
 An above novice-level of SQL authoring skills
 Cursory experience with SSAS and MDX

2 | 5/6/2016 | ABI Cube


About Me

 15 years of experience working with Microsoft


SQL Server
 Independent consultant working as a BI architect
and developer.
 Focus on SSAS and MDX

 Email: swatson@abicube.com
 Blog: https://shabnamwatson.wordpress.com
 Twitter: @shbWatson

3 | 5/6/2016 | ABI cube


Agenda

 Data Warehouse Concepts


 SSAS Multidimensional Data Model
 Measures/Dimensions
 MDX
 Capturing MDX Queries

4 | 5/6/2016 | ABI Cube


Multi Dimensional EXpressions (MDX)

• SQL Server 2012: SSAS Multi-Dimensional


(MD) and Tabular.

• MDX: Language of SSAS in MD.

• MDX queries.
• MDX script.

5 | 5/6/2016 | ABI Cube


Data Warehouse Concepts

• Fact tables
• Dimension tables
• Star Schema
• Joins

ABI cube
6 | 5/6/2016 |
SQL Server

Server

Database

Tables

7 | 5/6/2016 | ABI Cube


SSAS Data Model

Measure
Fact Tables Groups

Cube
Dimension
Dimensions
Tables

A multi-dimensional data structure: Detail Data and Aggregations.


Relationships between tables/objects already defined.

ABI cube
8 | 5/6/2016 |
SSAS Data Model
Sum of Sales Amount

Date 2005 Sales Amount

Slices
2006 Sales Amount
[Sales Amount]
2007 Sales Amount

2008 Sales Amount


Customer

Product All Products & Customers

9 | 5/6/2016 | ABI Cube


SSAS Server

AdevntureWorksDW2012Multidimensional

Server

Database

• Measure
Cube Groups
• Dimensions

10 | 5/6/2016 | ABI Cube


Measures

 Numerical Values
 Predefined aggregations
 Sum, Min, Max, Avg, …
 Measures return aggregated results unless
broken down by dimensions.

[Measures].[Internet Sales Amount]

11 | 5/6/2016 | ABI Cube


Dimensions

 DimDate
 [Date].[Calendar Quarter]

12 | 5/6/2016 | ABI Cube


Hierarchies

 Navigational Paths or Data Rollups


 Day  Month  Quarter Year

13 | 5/6/2016 | ABI Cube


User Defined Hierarchies

Attributes  Levels. All level: All Periods.

[Dimension].[Hierarchy].[Level].[Member]

[Date].[Calendar].[Calendar Quarter].[CY Q1]

14 | 5/6/2016 | ABI Cube


Attribute Hierarchies

Each attribute has a built in hierarchy with


the same name.
Two levels: All Level  Attribute Level

[Dimension].[Hierarchy].[Level].[Member]

[Date].[Calendar Quarter of Year].[Calendar Quarter of Year].[CY Q1]

[Date].[Calendar Quarter of Year].Members

[Date].[Calendar Quarter of Year].[Calendar Quarter of Year].Members

15 | 5/6/2016 | ABI Cube


Axis

Columns

 Columns 0
 Rows 1
Rows
 Pages 2
 Chapters 3
 Sections 4

16 | 5/6/2016 | ABI Cube


Parts of Query and Execution Stages
 With Set/Cal
From
Member…
 SELECT Where (Slicer)

 … ON COLUMNS With Set


 … ON ROWS Axis Independently

 FROM
Cells
 WHERE

17 | 5/6/2016 | ABI Cube


Columns Only Query
SELECT SUM([SalesAmount]) AS SalesAmount
FROM [dbo].[FactInternetSales]

SELECT {[Measures].[Internet Sales Amount]}


ON COLUMNS
FROM [Adventure Works]

SQL MDX
SELECT, FROM SELECT, FROM
SUM() Aggregation predefined.
From table. From Cube.

18 | 5/6/2016 | ABI Cube


Rows and Columns

SELECT dc.EnglishOccupation,SUM([SalesAmount]) AS
SalesAmount
FROM [dbo].[FactInternetSales] fIS
JOIN DimCustomer dc
ON fIS.CustomerKey = dc.CustomerKey
GROUP BY dc.EnglishOccupation

SELECT {[Measures].[Internet Sales Amount]} ON COLUMNS,


[Customer].[Occupation].[Occupation].MEMBERS ON ROWS
FROM [Adventure Works]

19 | 5/6/2016 | ABI Cube


More Basic Functions/Concepts
 {…,…,...}
 NON EMPTY
 WHERE
 MEMBERS
 TUPLE
 CALCULATED MEMBERS, CURRENTMEMBER
 CROSSJOIN

20 | 5/6/2016 | ABI Cube


Demo …

MDX SQL

21 | 5/6/2016 | ABI Cube


Functions to Learn Next
 NONEMPTY (not the same as NON EMPTY)
 FILTER
 ORDER
 CHILDREN
 DESCENDANTS

22 | 5/6/2016 | ABI Cube


Looking at MDX Queries
 Excel
 Free Pivot Table Extensions add in from CodePlex:
 https://olappivottableextend.codeplex.com/
 MDX tab --> Format with Web Service.

 SQL Server Profiler


 Trace
 Event: Query End.

23 | 5/6/2016 | ABI Cube


Demo …

MDX

24 | 5/6/2016 | ABI Cube


Pivot Table Extensions

25 | 5/6/2016 | ABI cube


Profiler

26 | 5/6/2016 | ABI Cube


Review
 Numeric Columns  Measures in Measure Groups
 Descriptive Columns  Attributes /Hierarchies in
Dimensions
 Grid:
 Axis: Rows and Columns
 Cells: Middle
 SELECT .. ON .. FROM … WHERE ….

27 | 5/6/2016 | ABI cube


Resources
 Books
 MDX Solutions: With Microsoft SQL Server Analysis
Services 2005 and Hyperion Essbase 2nd Edition.
 Microsoft SQL Server 2008 Analysis Services Unleashed
 Online
 MDX Language Reference
 https://msdn.microsoft.com/en-us/library/ms145595.aspx

28 | 5/6/2016 | ABI cube

You might also like