177
Introduction to MDX

Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

  • Upload
    vananh

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Introduction to MDX

Page 2: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

About Stacia

I have no life.

I never sleep.

I’ll sleep when I’m dead.

I’m ancient.

• BI consultant

• Author/co-author of

10 books about BI

• SQL Server MVP

• 12 years BI, 27 years

IT experience

Blog:

blog.datainspirations.com

Twitter: @StaciaMisner

Page 3: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Course Objectives

• Learn multidimensional concepts

• Develop basic multidimensional expressions

• Write MDX queries

• Create script assignments in a cube

• Implement granular security with MDX

• Learn optimization techniques

Page 4: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Prerequisites

• Basic understanding of relational database technology

• Basic understanding of Analysis Services

• No prior programming or SQL query development experience

is required

Page 5: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Course Outline

• Getting Started with MDX

• Building MDX Queries

• Defining Sets

• Adding Calculations to a Query

• Creating Calculations in a Cube

• MDX Scripting

• Implementing Security with MDX Expressions

• Optimizing MDX Queries

Page 6: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Getting Started with MDX

Page 7: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Module Overview

• Introducing MDX

• Comparing MDX with T-SQL

• Thinking about Multidimensional Space

• Exploring Options for Using MDX

Page 8: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Introducing MDX

• Multi-Dimensional eXpression

• Expression language

o Centralize business logic in cube

o Analogous to Excel formulas

• Query language

o Retrieve data from a cube

o Analogous to Transact-SQL

Page 9: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

MDX

• Query cubes for reporting and analysis

o Hyperion Essbase

o SAP Netweaver BI

o SAS OLAP Server

o SQL Server Analysis Services

• Reuse cube components

o Calculated member – formula evaluated at query run-time

o MDX script statement – expressions to override cell values under

specific conditions

o Key performance indicator – collection of formulas related to

comparison of a value to a target

• Modify cube components (Create, Alter, Delete)

Page 10: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Comparing MDX with T-SQL

Page 11: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Location, Location, Location

• Excel formulas require a cell reference (i.e. location)

• A cell reference on a single sheet uses two dimensions

o Column (letter) and row (number)

o Example: B2

Page 12: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Location, Location, Location

• Formulas using cells on multiple sheets use three

dimensions

– Sheet (name) and column (letter) and row (number)

– Example: ‘Sales 2008’!B2

Page 13: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Location, Location, Location

• Four dimensions

– Workbook, sheet, column, and row

– Example: '[Bikes.xlsx]Sales 2008'!$B$2

• Six dimensions

– Drive, folder, workbook, sheet, column, and row

– Example: 'C:\Sales\[Bikes.xlsx]Sales 2008'!$B$2

• Seven dimensions

– Server, drive, folder, workbook, sheet, column, and row

– Example: ‘\\SalesServer\C$\Sales\[Bikes.xlsx]Sales 2008'!$B$2

• Eight dimensions, nine dimensions,…and beyond!

Page 14: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Transitioning to Tuples: Two Dimensions

Mountain-200 Black

Road-250 Black

Touring-1000 Blue

(Road-250 Black, 2/1/2008)

(Mountain-200 Black, 1/1/2008)

$66,095.71

$83,562.57

Page 15: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Totals are Cells, Too

Mountain-200 Black

Road-250 Black

Touring-1000 Blue

(Road-250 Black, All Dates)

All Products

$4,831,250.71 $1,350,509.36

(All Products, All Dates)

Page 16: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Tuples in Three Dimensions

$66,095.71

All ProductsSales Amount

Order Quantity

Mountain-200 Black

Road-250 Black

Touring-1000 Blue

(All Products,

2/1/2008,

Order Quantity)

209

(Mountain-200 Black, 1/1/2008, Sales Amount)

Page 17: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Exploring Options for Using MDX

• Cube

o Calculated Members

o MDX Script (calculated cells)

o Actions

o Key Performance Indicators

o Security

• Presentation Layer

o Ad hoc query tools

• Manual: SSMS

• Automatic: BIDS, Excel

o Reports

• Reporting Services

• PerformancePoint Analytic

Reports

o SharePoint Filter Web Parts

o PerformancePoint KPIs and

dashboards

Page 18: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Building MDX Queries

Page 19: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Module Overview

• Understanding the MDX Query Editor

• Building Basic MDX Queries

• Adding Sets to a Query

Page 20: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Understanding the MDX Query Editor

• Using Object Explorer

• Exploring the Query Editor

• Metadata Pane

• Functions

Page 21: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Using Object Explorer

Connect to a server

View objects

and

metadata

Page 22: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Exploring the Query EditorToolbar buttons for common commands

Tab Groups

Color-coded text

Results and

messages

Page 23: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Metadata Pane: Measures

Measure Groups

Measure

Calculated Measure

Page 24: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Metadata Pane: Dimensions

Dimensions

Hierarchy

Attribute

Page 25: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Metadata Pane: User Hierarchies

User Hierarchies Hierarchy Level

Page 26: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Attribute Hierarchies vs User Hierarchies

• Attribute Hierarchy

o Two-level structure

• ‘All’ level

• Leaf level

o Can use to create ad hoc

hierarchies

• User Hierarchy

o Multi-level structure

• ‘All’ level

• One or more levels

• Might not include leaf

level

o Provides drill-down path

for users and query

optimizations

Page 27: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Metadata Pane: Members

Hierarchy levels

Member

[Product].[Product

Categories].[Category].&[1]

Member: Bikes

Page 28: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Functions

Page 29: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Functions: Set Functions

Page 30: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Basic Query Syntax: Simplest Query

SELECT

FROM <Cube>

All Products Sales AmountOrder Quantity

Mountain-200 Black

Road-250 Black

Touring-1000 Blue

Page 31: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Basic Query Syntax: Requesting a Tuple

SELECT

FROM <Cube>

WHERE

(Member1,Member2,...)

All Products Sales AmountOrder Quantity

Mountain-200 Black

Road-250 Black

Touring-1000 Blue

Page 32: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Referencing a Member

• UniqueName

o [Product].[Product].[Mountain-200 Black, 38]

• Alternatives

o [Product].[Mountain-200 Black, 38]

o Product. [Mountain-200 Black, 38]

o [Mountain-200 Black, 38]

• Precede member with

o Dimension name

o Hierarchy name

Page 33: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Referencing a Member

• Hierarchical referenceo [Product].[Products].[Product].[Mountain-200 Black, 38]

• Alternately precede member with

o Parent member

o Level name

• Key reference

o [Date].[Date].&[20080101]

Level Name

Key Column

Ampersand precedes key

Page 34: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Using Brackets in a Member Reference

• Embedded space

o Product.[Mountain Bikes]

• Reserved word

o [Date].&[2008]

• First character is not a letter or underscore

o [Date].Calendar.[2008]

• Does not contain characters other than letters,

underscores, or numbers

Page 35: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Basic Query Syntax: Single Axis

Select a single measure:

SELECT measure1 ON COLUMNS FROM cube

Select all measures:

SELECT [Measures].Members ON COLUMNS

FROM cube

Set

Page 36: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Basic Query Syntax: Two Axes

SELECT

measure1 ON COLUMNS,

dimension.Member ON ROWS

FROM cube

SELECT

measure1 ON 0,

dimension.Member ON 1

FROM cube

comma

Axis labels

Alternative labels

Page 37: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Basic Statement Structure: Two Axes

SELECT

dimension.Member ON ROWS,

measure1 ON COLUMNS

FROM cube

Order of axes doesn’t

matter

But with one axis only, you must use COLUMNS!

Page 38: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Adding Sets to a Query

• Multiple members from the same dimension and hierarchy

create a set

o List members and enclose in braces

o Single member set doesn’t need braces

• Many MDX functions create a set

SELECT

{measure1, measure2} ON COLUMNS,

dimension.hierarchy.Members ON ROWS

FROM cube

Braces for explicit members

Set functions:

• Members

• Children

• Descendants

• And more…

Page 39: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

All Products Sales AmountOrder Quantity

Mountain-200 Black

Road-250 Black

Touring-1000 Blue

Basic Query Syntax: Adding Columns

SELECT

<Set> ON COLUMNS

FROM <Cube>

WHERE

(Member1,Member2,...)

(Mountain-200 Black,

1/1/2008,

Sales Amount)

(Mountain-200 Black,

1/1/2008,

Order Quantity)

Page 40: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

All Products Sales AmountOrder Quantity

Mountain-200 Black

Road-250 Black

Touring-1000 Blue

Basic Query Syntax: Adding Rows

SELECT

<Set> ON COLUMNS,

<Set> ON ROWS

FROM <Cube>

WHERE

(Member1,Member2,...)

(All Products,

1/1/2008,

Sales Amount)

Page 41: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Basic Query Syntax: Variations

SELECT

<Set> On Columns

FROM <Cube>

SELECT

<Set> On 0

FROM <Cube>

Is

equivalent

to…

SELECT

<Set> On Columns,

<Set> On Rows,

FROM <Cube>

SELECT

<Set> On 0,

<Set> On 1

FROM <Cube>

Is

equivalent

to…

Page 42: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Basic Query Syntax: Variations

SELECT

<Set> On Rows

FROM <Cube>

Rows axis cannot stand alone

SELECT

<Set> On 1

FROM <Cube>

Page 43: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

How to Think about a Query

Rows and

columns

evaluated

independently

Tuples

constructedfrom

current row member

plus

current column

member

plus

WHERE clause

Page 44: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

How to Think about a Query

Rows and

columns

evaluated

independently

Tuples

constructedfrom

current row member

plus

current column

member

plus

WHERE clause

� Empty members removed if NON EMPTY on axis

Page 45: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Using the Cell Properties Clause

• Include the clause to retrieve formatted value, colors, etc.

• Add the clause at the end of the SELECT statement

SELECT

[Measures].[Sales Amount] On Columns

FROM [Adventure Works]

CELL PROPERTIES Formatted_Value;

Page 46: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Available Cell PropertiesCell Property Description

ACTION_TYPE Bitmask for type of action(s) assigned to cell

BACK_COLOR Bitmask for background color

CELL_ORDINAL Ordinal number of cell in cell set

FONT_FLAGS Bitmask for display for italic, bold, underline or strikeout

FONT_NAME Font name for display of value or formatted value

FONT_SIZE Font size for display of value or formatted value

FORE_COLOR Bitmask for foreground color

FORMAT Equivalent to FORMAT_STRING

FORMAT_STRING String defining format for value

FORMATTED_VALUE String display of value with formatting applied

LANGUAGE Locale to which format_string applies

UPDATEABLE Indicator whether the cell can be updated

VALUE Unformatted value of cell

Page 47: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Removing Empty Rows or Columns

• Use the NON EMPTY keyword on an axis to eliminate

empty tuples

SELECT

{measure1, measure2} ON COLUMNS,

NON EMPTY dimension.Members ON ROWS

FROM cube

Page 48: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Defining Sets

Page 49: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Module Overview

• Creating Sets with Functions

• Using Functions for Set Operations

• Working with Hierarchical Sets

Page 50: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Creating a Set with a Function

• Use .Members function to get all members of a level

o Dimension.Hierarchy.Members

o Dimension.Level.Members

• Use .AllMembers function to include calculated members

• Use braces and explicitly include members in a set

SELECT

[Sales Amount] ON 0,

[Product].[Category].Members ON

Rows

FROM [Adventure Works];

Page 51: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Using Sets in a Query

• On an axis (ON ROWS or ON COLUMNS)

• In the slicer (WHERE)

• As a calculation in query (WITH SET…)

• As a calculation in cube (CREATE SET…)

Page 52: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Using Functions for Set Operations

• Order

• Head (or Tail)

• TopCount (or BottomCount)

• Filter

• Crossjoin (using * operator)

Order([Product].[Product].Members,[Sales Amount],DESC)

Head([Product].[Product].Members,3)

TopCount([Product].[Product].Members,3,[Sales Amount])

Filter([Product].[Product].Members,[Sales Amount]>1000)

[Product].[Category].Members * [Date].[Calendar Year].Members

Page 53: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Order

Order(Set, Expression, Direction)

• Orders members by specified expression

• Expression can be numeric or string value

• Direction is ascending or descending – ASC, DESC

• Or hierarchical groupings ignored – BASC, DESC

select

{[Measures].[Sales Amount],

[Measures].[Order Quantity]} on columns,

Order(

[Product].[Product].[Product].Members,

[Measures].[Sales Amount], DESC) on rows

from Sales;

Page 54: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Head (Tail)

Head(Set, Integer)

• Filters the set to include only the number specified by

Integer beginning with the first member in set

select

{[Measures].[Sales Amount],

[Measures].[Order Quantity]} on columns,

Head(

[Product].[Product].[Product].Members,

2) on rows

from Sales;

Page 55: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

TopCount (BottomCount)

TopCount(Set, Integer, Measure)

• Orders members by measure in descending order

• Filters the ordered set to include only the number

specified by Integer

SELECT

[Sales Amount] ON 0,

TopCount(

[Product].Members,3,[Sales Amount])

ON ROWS

FROM [Adventure Works];

Page 56: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

• BottomCount

• TopPercent

• BottomPercent

• TopSum

• BottomSum

Variations of TopCount

Page 57: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Filter

Filter(Set, Expression)

• Filters the set to include only the members that meet the

specified condition

• Condition can compare string or numeric values

SELECT

[Sales Amount] ON COLUMNS,

Filter(

[Product].Members,[Sales Amount]>1000)

ON ROWS

FROM [Adventure Works];

Page 58: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

CrossJoin

CrossJoin(Set1, Set2) or Set1 * Set2

• Creates a set of tuples from two sets

• For more than two sets,

• Use nested CrossJoin functions or…

• Use * operator

select

{[Measures].[Sales Amount], [Measures].[Order Quantity]}

on columns,

non empty

Crossjoin(

[Product].[Subcategory].[Subcategory].Members,

[Date].[Calendar].[Year].Members) on rows

from Sales

Page 59: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Manipulating Sets

• Except

• Generate

• NonEmpty

• Extract

Page 60: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Except

Except(Set1, Set2)

• Creates a set of members that exist only in the first set

Except(

TopCount([Customer]),10,

([Prior Year Sales]),

TopCount([Customers]),10,

(Current Year Sales])

)

Page 61: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Generate

• Creates a new set by iteratively applying an expression to

a specified set

SELECT

[Sales Amount] ON COLUMNS,

Generate(

[Date].[Calendar].[Calendar Year].Members ,

[Date].[Calendar].CurrentMember *

TopCount(

[Product].[Product Categories].[Product].Members,

3,

[Measures].[Sales Amount])

)

ON ROWS

FROM [Adventure Works];

Generate(Set1, Set2)

Page 62: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Nonempty

NonEmpty(Set, Measure)

• Eliminates members that result in empty tuple with the

specified measure

SELECT

[Sales Amount] ON COLUMNS,

NonEmpty(

[Product].[Product].[Product].Members,

[Sales Amount]) ON ROWS

FROM [Adventure Works];

Page 63: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Extract

Extract(Set, Dimension.Hierarchy)

• Eliminates members that result in empty tuple with the

specified measure

SELECT

[Sales Amount] ON 0,

Extract(

NonEmpty(

([Product].[Product].Members,

[Sales Territory].[Sales Territories].[Europe],

[Date].[Year].[2004]),

[Sales Amount])

[Product].[Product])

ON ROWS

FROM [Adventure Works];

Page 64: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Defining an Asymmetrical Query

CY 2006 CY 2007

Sales Amount Sales Amount Order Quantity

• Use explicit tuples in sets

• Use same “hierarchality” in each tuple

{([CY 2006],[Sales Amount]),

([CY 2007],[Sales Amount]),

([CY 2007],[Order Quantity])}

Some OLAP browsers don’t

support asymmetrical queries

Page 65: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Using Functions and Keywords on the Axis

Use this To do this

Hierarchize To force the default dimension sort order

NON EMPTY To eliminate empty rows (or columns)

DIMENSION PROPERTIES

MEMBER_CAPTION

To retrieve captions

SELECT

[Sales Amount] ON COLUMNS,

NON EMPTY Hierarchize(«set»)

DIMENSION PROPERTIES MEMBER_CAPTION

ON ROWS

FROM <cube>

Page 66: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Working with Hierarchical Sets

• Parent

• Ancestor

• Children

• Descendants

• Siblings

• Other

Page 67: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Parent

• Returns the member above the current member

All Dates

2009

Q1 2009 Q2 2009

Apr 2009

May 2009

Jun 2009

Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

[July 2009].Parent

Page 68: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Ancestor

• Returns member above the current member at specified

levelAll Dates

2009

Q1 2009 Q2 2009

Apr 2009

May 2009

Jun 2009

Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

Ancestor([July 2009], [Year])

Page 69: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Children

• Returns a set of members below the current member

All Dates

2009

Q1 2009 Q2 2009

Apr 2009

May 2009

Jun 2009

Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

[Q3 2009].Children

Page 70: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Descendants

• Returns a set of members below the current member at

a specified distance or at a specific level

All Dates

2009

Q1 2009 Q2 2009

Apr 2009

May 2009

Jun 2009

Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

Descendants([2009], Month)

Page 71: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Siblings

• Returns a set of members on the same level and with the

same parent as the specified member

All Dates

2009

Q1 2009 Q2 2009

Apr 2009

May 2009

Jun 2009

Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

[July 2009].Siblings

Page 72: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Other Hierarchical Functions

• Ancestors

• Ascendants

• Cousin

• FirstChild

• FirstSibling

• LastChild

• LastSibling

Page 73: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Adding Calculations to a Query

Page 74: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Module Overview

• Understanding Types of Calculations

• Building Calculated Members

• Exploring More MDX Functions

Page 75: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Understanding Calculation Behavior

• Calculated Members

o New members added to a hierarchy at run time

• Scripts

o Replace the values that would otherwise be in part of a cube

o Appear to be procedural, but really define state formulas

• All calculations are ‘pull’ not ‘push’

• Results of calculations may be cached, but not persisted

Page 76: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Types of Calculations: Tuple-Based

• “Pct of Total” Example

([Road-250 Black, 44], [Sales Amount])

/ ([All Products], [Sales Amount])

• Analogous to Excel references: =B4/$B$2

Page 77: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Types of Calculations: Set-Based

• “YTD Sales” Example

Sum(YTD(), [Measures].[Sales Amount])

• Analogous to Excel ranges: =SUM($B$2:B5)

Page 78: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Building Calculated Members

WITH

MEMBER Measures.myMeasure1 AS expression1

MEMBER Measures.myMeasure2 AS expression2

SELECT

{Measures.myMeasure1, Measures.myMeasure2}

ON COLUMNS,

dimension.Member ON ROWS

FROM cube

WHERE (Members)

Add as many

calculations as you

need in WITH clause

Reference

calculations directly

or indirectly on

columns or rows

or in WHERE clause

Page 79: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Complete and Partial Tuples

• Complete Tupleo One member from each attribute hierarchy

o Required to retrieve a value

• Partial Tupleo Omits some attribute hierarchies

o May have as few as one attribute hierarchy

• Omitted hierarchies in partial tuple use CurrentMember

• CurrentMember Defined byo Row/column axes

o Slicer definition

o Default member

Page 80: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Tuples and Regular Cells

• Tuple Comes from Row,

Column, and Filter

([Accessories], [2002],

[A Bike Store], [Jiang,Stephen],[Order Quantity])

Page 81: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

([Order Quantity])

Tuples and Unspecified Hierarchies

• Unspecified attribute hierarchies use the current member [Order Date].[Calendar Year].

([Reseller Name].CurrentMember,[Sales Person Hierarchy].CurrentMember

[Order Date].[Calendar Year].CurrentMember,[Product Category].CurrentMember,

[Order Quantity])

Page 82: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Specifying a Member in a Tuple

• Constant

o [Sales Amount]

• Current Member

o Typically omit

• Function operating on Current Member

o [Date].CurrentMember.PrevMember

Page 83: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Miscellaneous Functions

• Level

o Returns a Level object

• Name

o Returns a String object

o Used to identify the following

• Dimension

• Level

• Member

• Properties

o Returns a String object

Dimension.Hierarchy.Name

Dimension.Hierarchy.Level.Name

Dimension.Hierarchy.Member.Name

Dimension.Hierarchy.Level

Dimension.Hierachy.Member.Properties(“PropertyName”)

Page 84: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Conditional Expressions

IIF (

[Measures].[Sales Amount] = 0

OR

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

NULL,

[Sales Amount]

/ ([All Products], [Sales Amount])

)

Boolean Expression

TRUE condition

FALSE condition

CASE statements are also valid in MDX

but IIF statements perform better

Page 85: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Exception Handling

• Test for Empty Cells

o IsEmpty

• Test for Existence of Member

o Is

IsEmpty((Product.Category.Bikes, [Sales Amount]))

Product.Category.CurrentMember IS Product.Category.Bikes

Page 86: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Building a Named Set

WITH

Set Set1 AS expression

SELECT

Measures.measure1 ON COLUMNS,

Set1 ON ROWS

FROM cube

Page 87: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Time-Series Analysis

• WTD, MTD, QTD, YTD

• ParallelPeriod()

• .PrevMember

• .Lag(n)

Page 88: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Functions for Time-Series Analysis

• PeriodsToDate

• xTD (WTD, MTD, QTD, YTD)

PeriodsToDate([Date].[Calendar].[Year])

All Dates

2010

Q1 2010

Q2 2010

Q3 2010

Q4 2010

{ Q1 2010}

{ Q1 2010, Q2 2010}

{ Q1 2010, Q2 2010, Q3 2010}

{ Q1 2010, Q2 2010, Q3 2010, Q4 2010}

YTD()

PeriodsToDate or YTD results by Date member:

Page 89: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

xTD

YTD([Date].Member)

• Similar to PeriodsToDate function

• Options: WTD, MTD, QTD, YTD

• Default date member: CurrentMember unless otherwise

specified

• Creates set from first period of year to specified member

SELECT

[Sales Amount] ON COLUMNS,

YTD([July 2009]) ON ROWS

FROM [Adventure Works];

Page 90: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

YTD with Month Member

All Dates

2009

Q1 2009

Jan 2009

Feb 2009

Mar 2009

Q2 2009

Apr 2009

May 2009

June 2009

Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

Oct 2009

Nov 2009

Dec 2009

Page 91: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

YTD with Quarter Member

All Dates

2009

Q1 2009

Jan 2009

Feb 2009

Mar 2009

Q2 2009

Apr 2009

May 2009

June 2009

Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

Oct 2009

Nov 2009

Dec 2009

Page 92: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

ParallelPeriod Function

All Dates

2008

Q1 2008 Q2 2008 Q3 2008

July 2008

Aug 2008

Sep 2008

Q4 2008

2009

Q1 2009 Q2 2009 Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

• Finds corresponding member of common ancestor

• Defaults to base from time current member

• With Level argument, controls common ancestor

• Only meaningful in User hierarchy

ParallelPeriod(

[Date].[Calendar Year].[Year],

1,

[July 2009])

ParallelPeriod(Level, Lag, Date.Member)

Page 93: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

PrevMember Function

• Returns previous member on same level

• Can be used with any hierarchy , but typically used with time hierarchy

• Assumes sequential importance

• Does not require user hierarchy

All Dates

2009

Q1 2009 Q2 2009 Q3 2009

July 2009

Aug 2009

Sep 2009

Q4 2009

Date.Calendar.Member.PrevMember

[Aug 2009].PrevMember

Page 94: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Lag

• Similar to PrevMember with greater “distance”

• Lag(n)

All Dates

2010

Q1 2010

Q2 2010

Q3 2010

Q4 2010

Q4 2009

Q1 2010

Q2 2010

Q3 2010

PrevMember or Lag(1) results by Date member:

Date.Calendar.Lag(n)

Page 95: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Creating Calculations in a Cube

Page 96: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Module Overview

• Creating Calculated Measures and Custom Members

• Defining Named Sets

• Creating KPIs

Page 97: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Creating Calculated Measures

New Calculated Member

Minimum definition:

• Name

• Parent hierarchy

• Parent member

(non-measure only)

• Expression

Form View

Page 98: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Creating Calculated Measures

Additional properties:

• Format string

• Visible

• Associated

measure group

• Display folder

Do not set non-empty behavior property

Optional expressions:

• Fore color

• Back color

• Font name

• Font size

• Font flag

Page 99: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Creating Calculated Measures

Create Member CurrentCube.[Measures].[Gross Profit Margin]As

([Measures].[Reseller Sales Amount]-[Measures].[Reseller Cost])/[Measures].[Reseller Sales Amount],

FORMAT_STRING = "Percent", FORE_COLOR = iif([Gross Profit Margin] < .10, 255 /*Red*/, 0 /*Black*/), VISIBLE = 1 , DISPLAY_FOLDER = 'Reseller Sales', ASSOCIATED_MEASURE_GROUP = 'Reseller Sales';

Script View

Page 100: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Creating Custom Members

CREATE MEMBER CURRENTCUBE.[Product].[Category].[All].[Other Products]AS Aggregate(

{[Product].[Category].&[Accessories], [Product].[Category].&[Clothing],[Product].[Category].&[Components]}

), FORMAT_STRING = case when Measures.CurrentMember is Measures.[Gross Profit Margin] then "Percent" when Measures.CurrentMember is Measures.[Reseller Order Quantity] then "#,#" else "Currency" end, VISIBLE = 1, language=1033 ;

Page 101: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Working with Custom Members

Available only in the designated hierarchy

No effect on dimension hierarchy’s aggregate values

Page 102: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Defining Named Sets

New Named Set

Minimum definition:

• Name

• Expression

• Type

• Dynamic

• Static

Form View

Page 103: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Defining Named Sets

CREATE DYNAMIC SET CURRENTCUBE.[Top 10 Products]AS

TopCount(

[Product].[Product Name].[Product Name].Members,10,[Measures].[Reseller Sales Amount]

), DISPLAY_FOLDER = 'Product Sets' ;

Script View

Page 104: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Working with Named Sets

Separate object in metadata tree

Placement in Filter

Pane to view members

in BIDS

selectMeasures.Members on columns,[Top 10 Products] on rowsfrom [Adventure Works DW]

Reference directly in queries

Page 105: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Creating KPIs

New KPI

What is the value to measure?

What is the target for comparison?

Page 106: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Creating KPIs

• How close is the value

to the target?

• What image displays

when the value is

close to or far from

the goal?

• How does the value

compare to a previous

period?

• In what direction

should the arrow

point?

Page 107: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Working with KPIs

Browser View

Set the date context in the Filter Pane

select{KPIValue("Gross Profit Margin"),KPIGoal("Gross Profit Margin"),KPIStatus("Gross Profit Margin"),KPITrend("Gross Profit Margin")}on columns,[Date].[Calendar].[CalendarYear].Members on rowsfrom [Adventure Works DW]

Page 108: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

MDX Scripting

Page 109: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Module Overview

• Introducing the MDX Script

• Adding Calculations to the MDX Script

• Debugging an MDX Script

Page 110: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Introducing the MDX Script

• Overwrite values in cube cells

• Execute multiple MDX statements within a defined scope

• Plan solve order more intuitively

• Use Find and Replace to make changes

Page 111: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

MDX Script Fundamentals

• Statements

o MDX Scripting statements: CALCULATE, SCOPE, etc.

o CREATE MEMBER

o CREATE SET

o Conditional statements

• Expressions

o Subcube

o Assignment expressions

All statements in an MDX script must be separated by a semicolon

Page 112: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

MDX Scripting Statement: CALCULATE

• Required statement in MDX script

• Used to populate each higher level cube cell with

aggregated value of lower level cells

• Changes to lower level cell values change the aggregated

value of high level cell

• “Last pass wins”

Page 113: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

CREATE MEMBER

• Optional propertieso FORMAT_STRING

o LANGUAGE

o SOLVE_ORDER

o VISIBLE

o NON_EMPTY_BEHAVIOR

o FORE_COLOR

o BACK_COLOR

o FONT_NAME

o FONT_SIZE

o FONT_FLAGS

Create Member CurrentCube.[Measures].[Reseller Gross Profit]

As [Measures].[Reseller Sales Amount]

-

[Measures].[Reseller Total Product Cost];

Page 114: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

CREATE SET

Create Dynamic Set CurrentCube.[Top 5 Products]

As TopCount(

[Product].[Product].Members,

5,

[Measures].[Sales Amount]

);

Page 115: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Conditional Statements: CASE…WHEN

Create Member CurrentCube.[Measures].[Ratio to Parent Product]

As

Case

When

[Product].[Product Model Categories].CurrentMember.Level.Ordinal

= 0

Then

1

Else

[Measures].[Sales Amount]

/

( [Product].[Product Model Categories].CurrentMember.Parent,

[Measures].[Sales Amount] )

End,

Format_String = "Percent" ;

Page 116: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Subcube

• A subset of cells contained in a cube

• All attribute hierarchies includedo If no members specified, just the All member

o Otherwise, one or more members as follows• A single member

• Some or all members of a single level

• Descendants of a single member

(

[Date].[CalendarYear].&[2005],

[Date].[Calendar].[Fiscal Quarter].Members,

[Measures].[Sales Amount Quota]

)

Page 117: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Assignment Expression

(

[Date].[CalendarYear].&[2005],

[Date].[Calendar].[Fiscal Quarter].Members,

[Measures].[Sales Amount Quota]

) = 800000;

Page 118: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Other MDX Scripting Statements

• SCOPE

• THIS

• FREEZE

Page 119: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

SCOPE and THIS

• Defines the current subcubeo All MDX expressions apply to subcube

o THIS function is reference to subcube

• Contains additional SCOPE statements as needed to further subdivide a subcube

SCOPE(

[Date].[CalendarYear].&[2005],

[Date].[Calendar].[Fiscal Quarter].Members,

[Measures].[Sales Amount Quota]

);

THIS = 8000000;

END SCOPE;

Page 120: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

FREEZE

• Protects cells from being overwritteno By subsequent expressions

o By aggregations resulting from CALCULATE

Freeze

(

[Date].[Calendar].[Fiscal Quarter].Members,

[Measures].[Sales Amount Quota]

) ;

Page 121: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Allocations with MDX Script

• Scenario

o Sales Quota data provided at quarterly level

o Sales Quota data not available at monthly level

o Sales Quota data not available for Q3 and Q4 2008

• Solution

o Allocate Sales Quota data to months

• Equal allocation for 2005

• Weighted allocation for all other years

o Compute Sales Quota data for 2008 from parallel period

Page 122: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Equal Allocation

Scope([Measures].[Sales Amount Quota]);Scope (

[Date].[Calendar Year].&[2005],[Date].[Calendar].[Month].Members

) ;

This = [Date].[Calendar].CurrentMember.Parent / 3 ;

End Scope ;

Page 123: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Prepare for Weighted Allocation

Freeze

(

[Date].[Calendar].[Quarter].Members,

[Measures].[Sales Amount Quota]

) ;

Scope

(

[Date].[Calendar Year].&[2007] : Null,

[Date].[Calendar].[Month].Members

) ;

Page 124: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Weight Computation

This =

( ParallelPeriod (

[Date].[Calendar].[CalendarYear], 1,

[Date].[Calendar].CurrentMember

),

[Measures].[Reseller Sales Amount]

)

/

( ParallelPeriod (

[Date].[Calendar].[CalendarYear], 1,

[Date].[Calendar].CurrentMember.Parent

),

[Measures].[Reseller Sales Amount]

) ;

Page 125: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Weight Allocation

This = [Measures].CurrentMember * [Date].[Calendar].Parent ;

End Scope ;

Page 126: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Compute from Parallel Period

Scope (

[Date].[Calendar Year].&[2008],{[Date].[Quarter].&[2008]&[3], [Date].[Quarter].&[2008]&[4]},[Date].[Calendar].[Quarter].Members

) ;

This = ParallelPeriod(

[Date].[Calendar].[CalendarYear], 1,[Date].[Calendar].CurrentMember

) * 1.35 ;

End Scope ;End Scope;

Page 127: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Implementing Security with MDX Expressions

Page 128: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Module Overview

• Configuring User Access

• Defining Dimension Security

• Configuring Cell-Level Security

• Implementing Dynamic Security

Page 129: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Configuring User Access

• Data Sources

o Read permission to access underlying data source required

only for specific data mining queries

• Dimensions

o Read permission to access dimension data, inherited by all

cubes that use dimension

• Dimension Data

o Grant (or deny) permission to view specified dimension

members and associated measures

o Use MDX expressions to configure permissions

Page 130: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Configuring User Access

• Cubeso Grant permission to access cube data, drill through to

underlying data, or access local cube

o Dimension access permissions inherited from dimension, unless overridden

• Cell Datao Grant (or deny) permission to view cell-level data

o Use MDX expressions to configure permissions

• Mining Structures and Mining Modelso Grant permission to access mining structures

o Grant permission to access, browse and drill through mining models

Page 131: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Defining Dimension Security

• Read or read/write

• Allowed set

• Denied set

• Default member

• Visual totals

Read/write permission at dimension level

requires

Read/write permission at cube level

Page 132: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Configuring Cell-Level Security

• Read permissions

o Allows user to view measure data

• Read contingent permissions

o Allows user to view calculated measure data if user has

permissions to view base measures

• Read / write permissions

o Allows user to perform write-back operations

Read/write permission at cell level requires

Read/write permission at cube level

Page 133: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Implementing Dynamic Security

• Create tables

o Users: User ID, UserName

o BridgeDimensionUsers: DimensionID, UserID

• Create dimension in BIDS for Users

• Create measure group in BIDS for BridgeDimensionUsers

• Create Allowed member set on Dimension

NonEmpty(Dimension.Hierarchy.Members(StrToMember(“[Users].[User].[“

+ UserName() + “]”),[Measures].[Bridge Dimension Users Count])

)

Page 134: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Optimizing MDX Queries

Page 135: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Module Overview

• Using SQL Server Profiler to Analyze Queries

• Optimizing Queries for the Formula Engine

• Optimizing Queries for the Storage Engine

Page 136: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Reviewing Potential Query Bottlenecks

• Network

• Query design

• Dimension design

• Aggregation design

• Linked dimensions or measure groups across servers

• ROLAP

• No partitions

• Remote partitions

• Dimension or cell writeback

Page 137: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Where Do You Start?

• Eliminate infrastructure bottlenecks

• Resolve resource contention issues

• Identify time required by the storage engine or the

formula engine to run query

• Use results to focus on optimization on query or

database design

Page 138: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Architecture Overview

Analysis Services Server

Client ApplicationMDX Query

Storage Engine

Formula Engine

Formula Engine Cache

Calculation Engine Subcube Operations

Dimension Data Measure Group Data

Storage Engine

Storage Engine CacheAttribute Store

Hierarchy Store

Aggregations

Fact Data

Compute Cell Data

Populate Axes

Query Parser

Page 139: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Formula Engine

• Retrieve Data

o Translation of request into subcube requests

• Produce Result Set

o Bulk calculation of subcube(s)….

o OR Cell-by-cell calculation

• Store Results in Cache

o Query Scope

o Session Scope

o Global Scope

Formula Engine Cache

Subcube Operations

Page 140: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Cell by Cell Computation

Measures.[Sales Amount]

Measures.[Product Contribution]

(Measures.[Sales Amount], Product.[Product Categories].Parent

/

=

Page 141: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Block Computation Logic

• Known Facts

o A = Product.CurrentMember

o B = Product.Parent

o Only when A is not null, A / B is not null

o B is always constant

o Storage Engine requests return non-null data only

Perform calculation only when:

- numerator values are returned by the Storage Engine- denominator is a constant value

New in SSAS 2008

Page 142: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Block Computation

Measures.[Sales Amount]

Measures.[Product Contribution]

(Measures.[Sales Amount], Product.[Product Categories].Parent

Step 1: Get non-null values from the Storage Engine

Step 2: Calculate the expression

Step 2: Add null values into the query results

Page 143: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Storage Engine: Dimensions

Attribute Store

Key Store

DataID Attribute Key Member

Property Store

DataID Attribute Property

Ordered by DataID for fast random access

Key Hash Name Hash

Relationship Store

DataIDs

Bitmap Indexes

Page 144: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Storage Engine: Dimensions

Hierarchy Store

Set Store

DataID

Structure Store (Parent level)

Level

IndexDataID

Parent

DataID

FirstChild

DataID

Children

Count

Path of each member

Applies only to natural hierarchies

Structure Store (Child level)

Level

IndexDataID

Parent

DataID

FirstChild

DataID

Children

Count

Page 145: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Storage Engine: Measure Groups

• Storage Engine Cacheo Loads as queries execute

o Clears with cleaner thread or processing of partition

• Aggregation Datao Responds to request with

aggregated values in storage

o Summarizes lower level aggregated values on-the-fly as needed

• Fact Datao Scans MOLAP partitions and

partitions segments in parallel

o Uses bitmap indexes to scan pages to find requested data

Storage Engine

Measure Group Data

Storage Engine

Storage Engine CacheAggregations

Fact Data

Page 146: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Which Engine is the Bottleneck?

• Time to execute query (cold cache)

o Storage Engine time = add elapsed time for each Query

Subcube event

o Formula Engine = Total execution time (Query End event)

– Storage Engine time

• Bottleneck is engine consuming 30% or more of total

query execution time

Page 147: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Prepare for Query

Clear Cache

Reload MDX Script (without caching)

Page 148: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

MDX Query

Page 149: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Query Results

Page 150: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Profiler Results Begin

• Query Begin indicates successful query parsing

• Serialize Results Current counts members on

each axis

Page 151: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Storage Engine Reads Partitions

Page 152: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Query Subcube Event

• Sum each Query Subcube Event to compute

total Storage Engine query time

• Review TextData for vectors returned to formula

engine…very cryptic

Page 153: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Query Subcube Verbose Event

• Use Query Subcube Verbose Event to

understand vectors

Page 154: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Subcube Details

Value Result

0 Default member returned

* All members returned

+ Selected members returned

- Slice below granularity returned

4 Single member’s DataID

Page 155: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Subcube Details

Page 156: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Profiler Results End

• Serialize Results Current reports total number of

cells in query results

• Query End reports total query duration

Page 157: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Duration Analysis

Page 158: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Optimizing Calculations

• Applying Conditional Logic Effectively

• Removing Empty Tuples

• Writing Efficient MDX

Page 159: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Applying Conditional Logic Effectively

• Use IIF or CASE statement

o FE calculates cell-by-cell in

calculation space

o Evaluates for each query

o Increases query response

time

• Use Scope Assignment

o FE calculates for range of cells

in calculation space

o Evaluates once

o Optimizes query performance

Best Practice!

Trade-offs between IIF and CASE:

• IIF faster - only two branches

• CASE easier to read than nested IIFs

Page 160: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

MDX Script

Page 161: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

MDX Query

Page 162: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Duration Analysis

• Query down from 64 ms

• FE down from 84%

Page 163: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Removing Empty Tuples

• Set functions return

nonempty and empty tuples

by default

• Elimination of empty tuples

optimizes queries

o Number of rows and/or

columns reduced

o Serialization faster with

nonempty tuples only

Best Practice!

Page 164: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

What is an Empty Tuple?

• No fact table record for the specified measure and

dimension combination

• Fact table record exists but contains null value for

measure

Tip: Set measure’s NullProcessing property to Preserve else SSAS converts to 0

Page 165: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

NON EMPTY Keyword

• Removes empty tuples from specified axis

• Fact table data

o Better query performance with sparse data

• Calculated data

o Slower query performance

o Requires evaluation of all cells in query before removing

empty tuples

o Note: Null values are treated as 0 in calculations NULL –

[Sales Amount] is not NULL

Page 166: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Analysis of NON EMPTY

• Query up from 46 ms

• FE down from 76%

• Query uses calculated

data

Page 167: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

NonEmpty Function

• NonEmpty function removes empty tuples from specified

set

• Don’t use calculated measure to find empty tuples

Page 168: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Analysis of NonEmpty Function

• Query up from 46 ms

• FE down from 73%

Page 169: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Exists Function

• Exists(Set,,”Measure Group”) function excludes tuples

not found in fact data

o Don’t do this

• Filter on member properties

o Do this

• NonEmpty and Exists

Page 170: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Analysis of Exists Function

• Query up from 61 ms

• FE down from 73%

Page 171: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Comparison Empty Tuples

0

10

20

30

40

50

60

70

80

90

CASE Statement SCOPE Statement NON EMPTY

keyword

NEB NonEmpty function Exists function

FE

SE

Page 172: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

MDX Functions to Avoid

• LookupCube

• NonEmptyCrossjoin

• LinkMember

• StrToSet or StrToMember

o Use server-side ADOMD.NET

• StrToValue

o Use .MemberValue

Worst Practice!

Page 173: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Using Subcubes

SELECT

measure1 ON COLUMNS,

dimension1.Member ON ROWS

FROM

(select dimension2.members ON COLUMNS from

(select dimension3.members ON COLUMNS from

cube))

Page 174: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Partitioning

• Create multiple partitions to enable optimal scans of fact

data

• Partition by one or more attributes used in many

queries, such as Year

o Number of records per partition

> 2 million and < 20 million

o Partition size

> 50 MB and < 250 MB Best Practice!

Page 175: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Aggregation Design: Tools

• Aggregation Design Wizard

o View aggregation candidates

o Update member and fact record counts

o Develop and apply aggregation design

• Usage-Based Optimization Wizard

o Capture query sampling in usage log

o Tune aggregation performance to actual usage

• Aggregation Utility (2005) / Aggregation Designer (2008)

o Override aggregation design algorithm

Best Practice!

Good Practice

Page 176: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Leveraging the FE Cache

• Not shared across multiple

sessions

o CREATE MEMBER –

single session scope

o WITH MEMBER –

single query scope

• Shared across multiple

sessions

o MDX Script –

global scope

Page 177: Introduction to MDX 2011 v2011 - Online Tutorials …dbmanagement.info/.../Essbase_introduction_to_mdx_2011.pdfo Calculated member –formula evaluated at query run-time o MDX script

Copyright © 2007-2011 by Data Inspirations Inc. All rights reserved.

Warming the Cache

• Cache is empty when server starts or partition processes

• Cache warming preloads general queries

o Create a VB.NET or C#.NET application

o Use ascmd.exe

o Add a script task to an Integration Services package

o Execute Reporting Services reports