尊敬的 微信汇率:1円 ≈ 0.046078 元 支付宝汇率:1円 ≈ 0.046168元 [退出登录]
SlideShare a Scribd company logo
Getting Started with MDX
Ron Moore
Topdown Consulting, Inc.
and
Monica Christie
Camuto Group
About Topdown consulting
Objective is to get you writing code fast
Quick intro - A LOT more to learn
Three sections
1. Queries
2. Basic member formulas
3. Beyond basics
You should already understand Essbase Outlines and
multidimensional concepts
Exercises use (modified) ASOSamp Application
One hierarchy has answers and one for your work
About the Workshop
Where is MDX used?
Queries for ASO and BSO
ASO member formulas and stored calcs
Smart View / Smart Query
Embedded in MaxL
Triggers, ASO Clear regions .
1 - Queries
MDX SCRIPT EDITOR
MDX Script Editor
Syntax basics and concepts
1 - Queries
Every number lives in an intersection
Every intersection has a name
One member name (coordinate) from each
(stored) dimension
Rule #1 of Multi-D databases
SELECT {Sales} ON COLUMNS
FROM [sample.basic]
{Year} ON ROWS
,
WHERE (East,Actual)
{[100]} ON AXIS (2)
,
A Simple Example 1 - Queries
SELECTSELECT
FROM [sample.basic]
Specifying Member Names
East or [2014] or [Gross Profit]
Markets.East or [Markets].[East]
Member only or Dimension.Member
● Dimension.member is best practice
● Dimension is required if it’s ambiguous
With or without square brackets
● Member name begins with a character other than a letter
● Member name has spaces
● Member name is also an MDX key word
Marketing Technologies Group | www.mtgny.com
Understanding Tuples and Sets
1 - Queries
Sets are Multiple Members
from One Dimension
SELECT { [Sales], [Profit] } ON COLUMNS,
{ [Qtr1], [Qtr2], [Qtr3], [Qtr4] } ON ROWS,
{ [Colas], [Root Beer], [Cream Soda] } ON AXIS(2)
FROM [sample.basic]
where ([East],[Actual])
Marketing Technologies Group | www.mtgny.com
A Set is:
• One or more members from the
same dimension
• Enclosed in braces
• Separated by commas
1 - Queries
Tuples Specify Intersections
SELECT { [Dec] , [Jan] } ON COLUMNS,
{ [Units],[Transactions] } ON ROWS
From [ASOSamp.Sample]
([Prev Year], ) ([Curr Year], )
Dec Jan
Units #Missing 42,228
Transactions #Missing 44,500
1 - Queries
Understanding Tuples
( [Actual],[Sales] )
( [Sales] )
( [Jan],[Actual],[Sales] )
1 - Queries
Understanding Tuples
Collection of member names separated by
commas, enclosed in parentheses
INTERSECTION! - No more than one member
from each dimension
Omit dimensions to include all elements of that
dimension
A tuple that specifies one member name from
each dimension is a single cell
Marketing Technologies Group | www.mtgny.com
1 - Queries
Understanding Sets
{ ( [Sales] ),
( [Prof % ]) }
{ ( [Sales], [P1] ),
([Prof % ], [P1] ) }
{ ( [Sales], [P1], [Jan] ),
( [Prof % ], [P1],[Jan] ) }
Marketing Technologies Group | www.mtgny.com
1 - Queries
Understanding Sets
Sets are collections of tuples separated
by commas, enclosed in braces { }
Tuples within a set must have the same
dimensions in the same order
Marketing Technologies Group | www.mtgny.com
1 - Queries
Syntax Review
Select - From - Where query structure
Specifying Member Names
● MemberName or [Member Name]
● [MemberName] or [Dim].[Member Name]
Tuples
● ( MemberName1, MemberName 2 )
● Only one member from each dimension
● Includes all members from missing dimensions
Sets
● { (Tuple1), (Tuple2) }
● Tuples must have same dims in same order
1 - Queries
members in our queries. Sets:
● Member-by-member
● Tuple-by-tuple
So far 1 - Queries
Now
MDX functions
● Children
● Descendants
● Generations
● Levels
Useful Functions 1 - Queries
Set of Children
{ [Qtr1].Children }
Or
{ Children([Qtr1]) }
Time
MTD
1st Half
Qtr1
Jan
Feb
Mar
Qtr2
Apr
May
Jun
1 - Queries
Set of Descendants
Syntax
Descendants ( member , [{ layer | index }[, Desc_flags ]])
Example
Descendants ( [N Amer], 2 , After )
Options
● Layer refers to a generation or level
● Index is n layers down from the member
● Flags specify relationships
•SELF
•AFTER
•BEFORE
•BEFORE_AND_AFTER
•SELF_AND_AFTER
•SELF_AND_BEFORE
•SELF_BEFORE_AFTER
•LEAVES
Marketing Technologies Group | www.mtgny.com
1 - Queries
Set of Descendants Part 1 - Queries
Marketing Technologies Group | www.mtgny.com
1 - QueriesWhat City?
Generations and Levels Functions
Syntax
● Dimension.Generations(#)
● Dimension.Levels(#)
Examples
● [Year].Generations(2).members
● [Year].Levels(0).members
Marketing Technologies Group | www.mtgny.com
1 - Queries
Generations Property
{[Year].Generations}
{[Year].Generations(2)}
{[Year].Generations(2).Members}
Gen1, Quarters, Months
{Quarters }
{ Qtr1, Qtr2, Qtr3, Qtr4 }
1 - Queries
1 - Queries
Select [Time].Levels(0).Members ON COLUMNS,
{ [Products].Generations(2).members} ON ROWS
FROM [KSCOPE14].[SAMPLE]
Select [Time].Levels(index).Members ON COLUMNS,
{ [Products].Generations(index).members} ON ROWS
FROM [KSCOPE14].[SAMPLE]
Generations and Levels Functions
Suppress missing rows and/or columns
SELECT NON EMPTY { [Qtr1].Children } ON COLUMNS,
NON EMPTY Descendants([Geography] ,2, After) ON ROWS
FROM [KSCOPE14].[Sample]
Non Empty
Exercises
Exercise
● 1 – My first query
● 2 – Creating intersection
● 3 – Functions: children and levels
● 4 – Functions: descendants and generations
Note: Please use KSCOPE14.sample
1 - Queries
2. Basic member
formulas
Simple Ratios 2 – member
formulas
Simple Ratios with Relative
References
([Jan], [Avg Units / Transaction] ) = ( [Jan], [Units] ) / ( [Jan], [Transactions])
Calculation POV from left side is passed to all terms on the right side
([Feb], [Avg Units / Transaction] ) = ( [Feb], [Units] ) / ( [Feb], [Transactions])
( [Avg Units / Transaction] ) = ( [Units] ) / ( [Transactions])
2 – member
formulas
Crossing One Dimension
Price = ( [Markets],[Price] )
Fixed (Absolute) References
( Share) = ( Sales) / ([Total Market] , Sales)
(NY, Share) = (NY, Sales) / ([Total Market] , Sales)
(MA,Share) = (MA,Sales) / ([Total Market] , Sales)
(CT, Share) = (CT, Sales) / ([Total Market] , Sales)
The POV from the left side is passed to all terms on the right side
Unless you override it with a member name
2 – member
formulas
Fixed References on Multiple
Dimensions
( Price) = (Market, Product, Price)
(NY, [Diet Cola], Price) = (Market, Product, Price )
(MA, Cola, Price) = (Market, Product, Price)
( CT, Cola, Price) = (Market, Product, Price)
2 – member
formulas
[Pct of Worldwide Units] = Units / “worldwide units”
[Pct of WW Units ] = Units / ( Geography, Units)
[Pct of All Ages WW Units] = Units / ( [Age Groups],Geography, Units)
Pct of Total
Trans Pct of Parent
Relative Reference
[Transactions]/
([Transactions],[Geography].CurrentMember.Parent)
Absolute Reference
[Transactions]/
([Transactions],[Geography].[Connecticut].Parent)
2 – member
formulas
2 – member
formulasTrans Pct of Parent
CurrentMember.parent = to nesting
functions
CT/North East
Sum of North East and South = 1
Geography 0 because it does not have
a parent
2 – member
formulasTrans Pct of Region x Prod Fam
Ancestor ( member, layer | index )
CurrentMember.parent = to nesting
functions
CT/North East
Sum of North East and South = 1
Geography 0 because it does not have
a parent
2 – member
formulasTrans Pct of Region x Prod Fam
Ancestor ( member, layer | index )
CurrentMember.parent = to nesting
functions
CT/North East
Sum of North East and South = 1
Geography 0 because it does not have
a parent
Bonus material
Parents on Two Dimensions
Two Dimensions with Parent
[Transactions]/
([Transactions],
[Geography].CurrentMember.Parent,
[Products].CurrentMember.Parent
)
Ancestors on Two Dimensions
Two Dims with Ancestor
[Transactions]/
([Transactions],
Ancestor ([Geography].CurrentMember,
[Geography].Generations(2)
),
Ancestor ([Products].CurrentMember,
[Products].Generations(2)
)
)
Part 3 Beyond Basics
IIF
CASE
Rolling calculations
IIF(Conditional test,True logic,False logic )
IIF(
IsUDA([Measures].currentmember, “Expense”),
[Prev Year] – [Curr Year],
[Curr Year] – [Prev Year]
)
IIF
CASE
When condition Then logic
Else (optional)
End
CASE
When IS([Time].Currentmember, [Qtr1])
Then [Mar]
End
Case
PrevMember and NextMember
Syntax
[Member].PrevMember
Example
[Sales] =
( [Sales],
[Year].CurrentMember.PrevMember
)
* 1.10
Marketing Technologies Group | www.mtgny.com
Lead and Lag
Syntax
member.Lag (index [,layertype ] [, hierarchy ] )
Example
[Sales] =
( [Sales],
[Year].CurrentMember.lag(2)
)
* 1.10
Rolling Calculations
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Prev Year 3 4 6 8 9 10 5 5 7 13 9 4
Curr Year 7 3 1 1 6 5 5 - - - - -
One Time Dimension
Two Time Dimensions
Functions Used
Avg ( set [,numeric_value_expression [,IncludeEmpty ] ])
Sum ( set [,numeric_value_expression ] )
LastPeriods(numeric_value_expression[,member[,hierarchy]] )
Count ( set [, IncludeEmpty] )
Rolling Calculations Step by Step
1. Create a Simple Average()
2. Create a range with LastPeriods()
3. Make range relative with .CurrentMember
Avg ( LastPeriods(6, Jun ) , Units)
Rolling Average Example
Avg ( {Jan : Jun } , Units)
Avg ( LastPeriods(6, [Time].Currentmember ), Units)
2D Rolling Calcs
Number of months needed from previous year changes
each month
“Count” the months available in the Currentmember
year
● Count(LastPeriods(6,[Time].Currentmember)
Subtract to get months needed from previous year
● 6 - Count(LastPeriods(6,[Time].Currentmember)
Use the difference relative to Dec
● LastPeriods(
6 - Count(LastPeriods(6,[Time].CurrentMember)),
Dec )
2D Rolling Calc Example
Sum(LastPeriods(6,[Time].Currentmember),Units)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Previous Year 4 4 8 1 1 8 4 9 9 5 5 4
Current Year 8 8 9 7 2 2 9 10 2 6 7 7
9 5 5 4
+ Sum ( set
[,numeric_value_expression ] )
Months NA This Yr
, Last Year’s Units ), (Units,[Years].Currentmember.Prevmember)
LastPeriods(6 - count(LastPeriods(6,[Time].Currentmember))
, Dec)
Thank you for attending
The End
Deleted Slides
Levels and Generations
Function form and property form
Generations and Levels refers to a specific layer
number
Specific generation or level
Dimension.Generations ( GenNum )
Dimension.Levels ( LevNum )
Marketing Technologies Group | www.mtgny.com
A Set of Ancestors
Ancestors ( member , layer | index )
e.g. Ancestors ( Jan , 2 )
Marketing Technologies Group | www.mtgny.com
Set of Ancestors
,
Example:
Simple Assignments and Ratios
Profit Pct
Marketing Technologies Group | www.mtgny.com
Marketing Technologies Group | www.mtgny.com
Essbase Calc
Language
“Gross Profit” / “Net Sales”;
MDX [Gross profit] / [Net Sales]
Example:
Inventory Balance Forward
Marketing Technologies Group | www.mtgny.com
Essbase Calc
Language
@Prior(Inventory)
+”Inventory Change”;
MDX ([Measures].[Inventory],
[Year].CurrentMember.PrevMember )
+
( [Measures].[Inventory Change] )
Example: Referring to Relatives
Share of Region
Marketing Technologies Group | www.mtgny.com
Essbase
Calc
Units /@Ancestval(“Market Total”, 3, Units );
MDX
[Units] /
( [Units],
Ancestor([Market Total].CurrentMember,
[Market Total].Generations(3) )
)
Thank you
Thanks for joining
Please email me your comments:
● Your success level
● Speed of presentation
● Quality/Accuracy of documentation
● Effective/ineffective slides and presentations
● Email questions on content and solutions
● rmoore@topdownconsulting.com and/or
monica.christie@camutogroup.com
CrossJoin()
Crossjoin() creates the Cartesian product of two sets
Crossjoin( { Jan, Feb }, {[2006], [2007]} )
returns
{(Jan,[2006]),(Jan,[2007]),(Feb,[2006]), (Feb, [2007])}
Notes
● Only 2 sets at time –nest crossjoins for more than 2
● Second set changes fastest
Marketing Technologies Group | www.mtgny.com
Descendants Using Layer
Layer (Reset layer)
QTD YTD
Gen5 Jan Jan Jan
Gen5 Feb Jan+Feb Jan+Feb
Gen5 Mar Jan+Feb+Mar Jan+Feb+Mar
Gen4 Qtr1 Reset
Gen5 Apr Apr Jan+Feb+Mar+Apr
Gen5 May Apr+May Jan+Feb+Mar+Apr+May
Gen5 Jun Apr+May+Jun Jan+Feb+Mar+Apr+May+Jun
Gen4 Qtr2 Reset
Gen3 1st Half
Gen5 Jul Jul Jan+Feb+Mar+Apr+May+Jun+Jul
Gen5 Aug Jul+Aug Jan+Feb+Mar+Apr+May+Jun+Jul+Aug
Gen5 Sep Jul+Aug+Sep Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep
Gen4 Qtr3 Reset
Gen5 Oct Oct Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+Oct
Gen5 Nov Oct+Nov Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+Oct+Nov
Gen5 Dec Oct+Nov+Dec Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+Oct+Nov+Dec
Gen4 Qtr4 Reset
Gen3 2nd Half
Gen2 Year Total Reset
Gen1 Time
Periods to Date
Year To Date
Sum(
{PeriodsToDate ([Time].Generations(2),
[Time].CurrentMember )
}
)
Quarter to Date
Sum(
{PeriodsToDate ([Time].Generations(4),
[Time].CurrentMember )
}
)
Create a Simple Average
Syntax:
Avg ( set [,numeric_expression [,IncludeEmpty ] ])
Example:
Avg ({Jan:Jun}, Units)
LastPeriods() to Create a Range
Syntax:
LastPeriods ( numeric_expression [, member [, hierarchy ]
] )
Example:
Avg (
LastPeriods( 6, Jun),
Units)
Marketing Technologies Group | www.mtgny.com
.CurrentMember
to Make the Range Relative
Example:
Avg (
LastPeriods (6, [Time].CurrentMember),
Units)
Marketing Technologies Group | www.mtgny.com
Syntax Review #1
Select - From - Where query structure
MemberName or [Member Name]
[MemberName] or [Dim].[Member Name]
{ MemberName1, [Member Name2] }
Marketing Technologies Group | www.mtgny.com
Using Generation or Level Names
Share of Ancestor
[Transactions]/
( [Transactions],
Ancestor ( [Geography].CurrentMember,
[Geography].Generations(2)
)
)
Ancestor ( member ,
layer | index
[, hierarchy ]
)

More Related Content

Viewers also liked

Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
Doug Armantrout
 
Citrix MDX Technologies Feature Brief
Citrix MDX Technologies Feature BriefCitrix MDX Technologies Feature Brief
Citrix MDX Technologies Feature Brief
Nuno Alves
 
Ssis sql ssrs_sp_ssas_mdx_hb_li
Ssis sql ssrs_sp_ssas_mdx_hb_liSsis sql ssrs_sp_ssas_mdx_hb_li
Ssis sql ssrs_sp_ssas_mdx_hb_li
Hong-Bing Li
 
SQL Server Analysis Services and MDX
SQL Server Analysis Services and MDXSQL Server Analysis Services and MDX
SQL Server Analysis Services and MDX
Mark Ginnebaugh
 
Enhancing Dashboard Visuals with Multi-Dimensional Expressions (MDX)
Enhancing Dashboard Visuals with Multi-Dimensional Expressions (MDX)Enhancing Dashboard Visuals with Multi-Dimensional Expressions (MDX)
Enhancing Dashboard Visuals with Multi-Dimensional Expressions (MDX)
Daniel Upton
 
Introduction to mdx query ppt
Introduction to mdx query pptIntroduction to mdx query ppt
Introduction to mdx query ppt
Shankar Murugappan
 
Mdx complex-queries-130019
Mdx complex-queries-130019Mdx complex-queries-130019
Mdx complex-queries-130019
Sabyasachi Srimany
 
Multidimensional expressions mdx - reference
Multidimensional expressions   mdx - referenceMultidimensional expressions   mdx - reference
Multidimensional expressions mdx - reference
Steve Xu
 
2012 Acura MDX Brochure | DCH Acura of Temecula
2012 Acura MDX Brochure | DCH Acura of Temecula2012 Acura MDX Brochure | DCH Acura of Temecula
2012 Acura MDX Brochure | DCH Acura of Temecula
DCH Acura of Temecula
 
Mdx university dubai courses
Mdx university dubai coursesMdx university dubai courses
Mdx university dubai courses
anjam tm
 
rmoore.smartquery KScope15
rmoore.smartquery KScope15rmoore.smartquery KScope15
rmoore.smartquery KScope15
Ron Moore
 
Moore Advanced Calculations in Calc Manager OW 20151015
Moore Advanced Calculations in Calc Manager  OW 20151015Moore Advanced Calculations in Calc Manager  OW 20151015
Moore Advanced Calculations in Calc Manager OW 20151015
Ron Moore
 
MDX 2015-2019 Work Program Overview presentation, October 22, 2014
MDX 2015-2019 Work Program Overview presentation, October 22, 2014MDX 2015-2019 Work Program Overview presentation, October 22, 2014
MDX 2015-2019 Work Program Overview presentation, October 22, 2014
Miami-Dade Transportation Planning Organization
 
IBM Cognos Dimensional Dashboarding Techniques
IBM Cognos Dimensional Dashboarding TechniquesIBM Cognos Dimensional Dashboarding Techniques
IBM Cognos Dimensional Dashboarding Techniques
Senturus
 
Ssis sql ssrs_ssas_sp_mdx_hb_li
Ssis sql ssrs_ssas_sp_mdx_hb_liSsis sql ssrs_ssas_sp_mdx_hb_li
Ssis sql ssrs_ssas_sp_mdx_hb_li
Hong-Bing Li
 
SSRS for DBA's
SSRS for DBA'sSSRS for DBA's
SSRS for DBA's
Jonathan Bloom
 
Big Data MDX with Mondrian and Apache Kylin
Big Data MDX with Mondrian and Apache KylinBig Data MDX with Mondrian and Apache Kylin
Big Data MDX with Mondrian and Apache Kylin
inovex GmbH
 
Essbase Calculations A Visual Approach KScope 2010
Essbase Calculations A Visual Approach KScope 2010Essbase Calculations A Visual Approach KScope 2010
Essbase Calculations A Visual Approach KScope 2010
Ron Moore
 
SSAS and MDX
SSAS and MDXSSAS and MDX
SSAS and MDX
carmenfaber
 
Geo spatial analytics using Microsoft BI
Geo spatial analytics using Microsoft BIGeo spatial analytics using Microsoft BI
Geo spatial analytics using Microsoft BI
Jason Thomas
 

Viewers also liked (20)

Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Citrix MDX Technologies Feature Brief
Citrix MDX Technologies Feature BriefCitrix MDX Technologies Feature Brief
Citrix MDX Technologies Feature Brief
 
Ssis sql ssrs_sp_ssas_mdx_hb_li
Ssis sql ssrs_sp_ssas_mdx_hb_liSsis sql ssrs_sp_ssas_mdx_hb_li
Ssis sql ssrs_sp_ssas_mdx_hb_li
 
SQL Server Analysis Services and MDX
SQL Server Analysis Services and MDXSQL Server Analysis Services and MDX
SQL Server Analysis Services and MDX
 
Enhancing Dashboard Visuals with Multi-Dimensional Expressions (MDX)
Enhancing Dashboard Visuals with Multi-Dimensional Expressions (MDX)Enhancing Dashboard Visuals with Multi-Dimensional Expressions (MDX)
Enhancing Dashboard Visuals with Multi-Dimensional Expressions (MDX)
 
Introduction to mdx query ppt
Introduction to mdx query pptIntroduction to mdx query ppt
Introduction to mdx query ppt
 
Mdx complex-queries-130019
Mdx complex-queries-130019Mdx complex-queries-130019
Mdx complex-queries-130019
 
Multidimensional expressions mdx - reference
Multidimensional expressions   mdx - referenceMultidimensional expressions   mdx - reference
Multidimensional expressions mdx - reference
 
2012 Acura MDX Brochure | DCH Acura of Temecula
2012 Acura MDX Brochure | DCH Acura of Temecula2012 Acura MDX Brochure | DCH Acura of Temecula
2012 Acura MDX Brochure | DCH Acura of Temecula
 
Mdx university dubai courses
Mdx university dubai coursesMdx university dubai courses
Mdx university dubai courses
 
rmoore.smartquery KScope15
rmoore.smartquery KScope15rmoore.smartquery KScope15
rmoore.smartquery KScope15
 
Moore Advanced Calculations in Calc Manager OW 20151015
Moore Advanced Calculations in Calc Manager  OW 20151015Moore Advanced Calculations in Calc Manager  OW 20151015
Moore Advanced Calculations in Calc Manager OW 20151015
 
MDX 2015-2019 Work Program Overview presentation, October 22, 2014
MDX 2015-2019 Work Program Overview presentation, October 22, 2014MDX 2015-2019 Work Program Overview presentation, October 22, 2014
MDX 2015-2019 Work Program Overview presentation, October 22, 2014
 
IBM Cognos Dimensional Dashboarding Techniques
IBM Cognos Dimensional Dashboarding TechniquesIBM Cognos Dimensional Dashboarding Techniques
IBM Cognos Dimensional Dashboarding Techniques
 
Ssis sql ssrs_ssas_sp_mdx_hb_li
Ssis sql ssrs_ssas_sp_mdx_hb_liSsis sql ssrs_ssas_sp_mdx_hb_li
Ssis sql ssrs_ssas_sp_mdx_hb_li
 
SSRS for DBA's
SSRS for DBA'sSSRS for DBA's
SSRS for DBA's
 
Big Data MDX with Mondrian and Apache Kylin
Big Data MDX with Mondrian and Apache KylinBig Data MDX with Mondrian and Apache Kylin
Big Data MDX with Mondrian and Apache Kylin
 
Essbase Calculations A Visual Approach KScope 2010
Essbase Calculations A Visual Approach KScope 2010Essbase Calculations A Visual Approach KScope 2010
Essbase Calculations A Visual Approach KScope 2010
 
SSAS and MDX
SSAS and MDXSSAS and MDX
SSAS and MDX
 
Geo spatial analytics using Microsoft BI
Geo spatial analytics using Microsoft BIGeo spatial analytics using Microsoft BI
Geo spatial analytics using Microsoft BI
 

Similar to Getting Started with MDX 20140625a

Mdx basics
Mdx basicsMdx basics
Mdx basics
Jason Thomas
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
eileensauer
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
eileensauer
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
Chris Seebacher
 
Recommender System with Distributed Representation
Recommender System with Distributed RepresentationRecommender System with Distributed Representation
Recommender System with Distributed Representation
Rakuten Group, Inc.
 
Programming in R
Programming in RProgramming in R
Programming in R
Smruti Sarangi
 
GPU Accelerated Backtesting and Machine Learning for Quant Trading Strategies
GPU Accelerated Backtesting and Machine Learning for Quant Trading StrategiesGPU Accelerated Backtesting and Machine Learning for Quant Trading Strategies
GPU Accelerated Backtesting and Machine Learning for Quant Trading Strategies
Daniel Egloff
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
Databricks
 
Data structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 pptData structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 ppt
aviban
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
guest3ea163
 
dplyr Package in R
dplyr Package in Rdplyr Package in R
dplyr Package in R
Vedant Shah
 
Dax queries.pdf
Dax queries.pdfDax queries.pdf
Dax queries.pdf
ntrnbk
 
Company segmentation - an approach with R
Company segmentation - an approach with RCompany segmentation - an approach with R
Company segmentation - an approach with R
Casper Crause
 
Olap fundamentals
Olap fundamentalsOlap fundamentals
Olap fundamentals
Amit Sharma
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
RaajTech
 
SQL Server part 1 (6).pptx
SQL Server part 1 (6).pptxSQL Server part 1 (6).pptx
SQL Server part 1 (6).pptx
deepneuron
 
Tableau PPT
Tableau PPTTableau PPT
Tableau PPT
Anvesh Rao
 
Tableau ppt
Tableau pptTableau ppt
SSAS Project Profile
SSAS Project ProfileSSAS Project Profile
SSAS Project Profile
tthompson0421
 
Data ware dimension design
Data ware   dimension designData ware   dimension design
Data ware dimension design
Sayed Ahmed
 

Similar to Getting Started with MDX 20140625a (20)

Mdx basics
Mdx basicsMdx basics
Mdx basics
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Recommender System with Distributed Representation
Recommender System with Distributed RepresentationRecommender System with Distributed Representation
Recommender System with Distributed Representation
 
Programming in R
Programming in RProgramming in R
Programming in R
 
GPU Accelerated Backtesting and Machine Learning for Quant Trading Strategies
GPU Accelerated Backtesting and Machine Learning for Quant Trading StrategiesGPU Accelerated Backtesting and Machine Learning for Quant Trading Strategies
GPU Accelerated Backtesting and Machine Learning for Quant Trading Strategies
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
 
Data structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 pptData structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 ppt
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
 
dplyr Package in R
dplyr Package in Rdplyr Package in R
dplyr Package in R
 
Dax queries.pdf
Dax queries.pdfDax queries.pdf
Dax queries.pdf
 
Company segmentation - an approach with R
Company segmentation - an approach with RCompany segmentation - an approach with R
Company segmentation - an approach with R
 
Olap fundamentals
Olap fundamentalsOlap fundamentals
Olap fundamentals
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
SQL Server part 1 (6).pptx
SQL Server part 1 (6).pptxSQL Server part 1 (6).pptx
SQL Server part 1 (6).pptx
 
Tableau PPT
Tableau PPTTableau PPT
Tableau PPT
 
Tableau ppt
Tableau pptTableau ppt
Tableau ppt
 
SSAS Project Profile
SSAS Project ProfileSSAS Project Profile
SSAS Project Profile
 
Data ware dimension design
Data ware   dimension designData ware   dimension design
Data ware dimension design
 

Getting Started with MDX 20140625a

  • 1. Getting Started with MDX Ron Moore Topdown Consulting, Inc. and Monica Christie Camuto Group
  • 3. Objective is to get you writing code fast Quick intro - A LOT more to learn Three sections 1. Queries 2. Basic member formulas 3. Beyond basics You should already understand Essbase Outlines and multidimensional concepts Exercises use (modified) ASOSamp Application One hierarchy has answers and one for your work About the Workshop
  • 4. Where is MDX used? Queries for ASO and BSO ASO member formulas and stored calcs Smart View / Smart Query Embedded in MaxL Triggers, ASO Clear regions .
  • 5. 1 - Queries MDX SCRIPT EDITOR MDX Script Editor
  • 6. Syntax basics and concepts 1 - Queries
  • 7. Every number lives in an intersection Every intersection has a name One member name (coordinate) from each (stored) dimension Rule #1 of Multi-D databases
  • 8. SELECT {Sales} ON COLUMNS FROM [sample.basic] {Year} ON ROWS , WHERE (East,Actual) {[100]} ON AXIS (2) , A Simple Example 1 - Queries SELECTSELECT FROM [sample.basic]
  • 9. Specifying Member Names East or [2014] or [Gross Profit] Markets.East or [Markets].[East] Member only or Dimension.Member ● Dimension.member is best practice ● Dimension is required if it’s ambiguous With or without square brackets ● Member name begins with a character other than a letter ● Member name has spaces ● Member name is also an MDX key word Marketing Technologies Group | www.mtgny.com
  • 10. Understanding Tuples and Sets 1 - Queries
  • 11. Sets are Multiple Members from One Dimension SELECT { [Sales], [Profit] } ON COLUMNS, { [Qtr1], [Qtr2], [Qtr3], [Qtr4] } ON ROWS, { [Colas], [Root Beer], [Cream Soda] } ON AXIS(2) FROM [sample.basic] where ([East],[Actual]) Marketing Technologies Group | www.mtgny.com A Set is: • One or more members from the same dimension • Enclosed in braces • Separated by commas 1 - Queries
  • 12. Tuples Specify Intersections SELECT { [Dec] , [Jan] } ON COLUMNS, { [Units],[Transactions] } ON ROWS From [ASOSamp.Sample] ([Prev Year], ) ([Curr Year], ) Dec Jan Units #Missing 42,228 Transactions #Missing 44,500 1 - Queries
  • 13. Understanding Tuples ( [Actual],[Sales] ) ( [Sales] ) ( [Jan],[Actual],[Sales] ) 1 - Queries
  • 14. Understanding Tuples Collection of member names separated by commas, enclosed in parentheses INTERSECTION! - No more than one member from each dimension Omit dimensions to include all elements of that dimension A tuple that specifies one member name from each dimension is a single cell Marketing Technologies Group | www.mtgny.com 1 - Queries
  • 15. Understanding Sets { ( [Sales] ), ( [Prof % ]) } { ( [Sales], [P1] ), ([Prof % ], [P1] ) } { ( [Sales], [P1], [Jan] ), ( [Prof % ], [P1],[Jan] ) } Marketing Technologies Group | www.mtgny.com 1 - Queries
  • 16. Understanding Sets Sets are collections of tuples separated by commas, enclosed in braces { } Tuples within a set must have the same dimensions in the same order Marketing Technologies Group | www.mtgny.com 1 - Queries
  • 17. Syntax Review Select - From - Where query structure Specifying Member Names ● MemberName or [Member Name] ● [MemberName] or [Dim].[Member Name] Tuples ● ( MemberName1, MemberName 2 ) ● Only one member from each dimension ● Includes all members from missing dimensions Sets ● { (Tuple1), (Tuple2) } ● Tuples must have same dims in same order 1 - Queries
  • 18. members in our queries. Sets: ● Member-by-member ● Tuple-by-tuple So far 1 - Queries Now MDX functions ● Children ● Descendants ● Generations ● Levels
  • 19. Useful Functions 1 - Queries
  • 20. Set of Children { [Qtr1].Children } Or { Children([Qtr1]) } Time MTD 1st Half Qtr1 Jan Feb Mar Qtr2 Apr May Jun 1 - Queries
  • 21. Set of Descendants Syntax Descendants ( member , [{ layer | index }[, Desc_flags ]]) Example Descendants ( [N Amer], 2 , After ) Options ● Layer refers to a generation or level ● Index is n layers down from the member ● Flags specify relationships •SELF •AFTER •BEFORE •BEFORE_AND_AFTER •SELF_AND_AFTER •SELF_AND_BEFORE •SELF_BEFORE_AFTER •LEAVES Marketing Technologies Group | www.mtgny.com 1 - Queries
  • 22. Set of Descendants Part 1 - Queries
  • 23. Marketing Technologies Group | www.mtgny.com 1 - QueriesWhat City?
  • 24. Generations and Levels Functions Syntax ● Dimension.Generations(#) ● Dimension.Levels(#) Examples ● [Year].Generations(2).members ● [Year].Levels(0).members Marketing Technologies Group | www.mtgny.com 1 - Queries
  • 26. 1 - Queries Select [Time].Levels(0).Members ON COLUMNS, { [Products].Generations(2).members} ON ROWS FROM [KSCOPE14].[SAMPLE] Select [Time].Levels(index).Members ON COLUMNS, { [Products].Generations(index).members} ON ROWS FROM [KSCOPE14].[SAMPLE] Generations and Levels Functions
  • 27. Suppress missing rows and/or columns SELECT NON EMPTY { [Qtr1].Children } ON COLUMNS, NON EMPTY Descendants([Geography] ,2, After) ON ROWS FROM [KSCOPE14].[Sample] Non Empty
  • 28. Exercises Exercise ● 1 – My first query ● 2 – Creating intersection ● 3 – Functions: children and levels ● 4 – Functions: descendants and generations Note: Please use KSCOPE14.sample 1 - Queries
  • 30. Simple Ratios 2 – member formulas
  • 31. Simple Ratios with Relative References ([Jan], [Avg Units / Transaction] ) = ( [Jan], [Units] ) / ( [Jan], [Transactions]) Calculation POV from left side is passed to all terms on the right side ([Feb], [Avg Units / Transaction] ) = ( [Feb], [Units] ) / ( [Feb], [Transactions]) ( [Avg Units / Transaction] ) = ( [Units] ) / ( [Transactions]) 2 – member formulas
  • 32. Crossing One Dimension Price = ( [Markets],[Price] )
  • 33. Fixed (Absolute) References ( Share) = ( Sales) / ([Total Market] , Sales) (NY, Share) = (NY, Sales) / ([Total Market] , Sales) (MA,Share) = (MA,Sales) / ([Total Market] , Sales) (CT, Share) = (CT, Sales) / ([Total Market] , Sales) The POV from the left side is passed to all terms on the right side Unless you override it with a member name 2 – member formulas
  • 34. Fixed References on Multiple Dimensions ( Price) = (Market, Product, Price) (NY, [Diet Cola], Price) = (Market, Product, Price ) (MA, Cola, Price) = (Market, Product, Price) ( CT, Cola, Price) = (Market, Product, Price) 2 – member formulas
  • 35. [Pct of Worldwide Units] = Units / “worldwide units” [Pct of WW Units ] = Units / ( Geography, Units) [Pct of All Ages WW Units] = Units / ( [Age Groups],Geography, Units) Pct of Total
  • 36. Trans Pct of Parent Relative Reference [Transactions]/ ([Transactions],[Geography].CurrentMember.Parent) Absolute Reference [Transactions]/ ([Transactions],[Geography].[Connecticut].Parent) 2 – member formulas
  • 37. 2 – member formulasTrans Pct of Parent CurrentMember.parent = to nesting functions CT/North East Sum of North East and South = 1 Geography 0 because it does not have a parent
  • 38. 2 – member formulasTrans Pct of Region x Prod Fam Ancestor ( member, layer | index ) CurrentMember.parent = to nesting functions CT/North East Sum of North East and South = 1 Geography 0 because it does not have a parent
  • 39. 2 – member formulasTrans Pct of Region x Prod Fam Ancestor ( member, layer | index ) CurrentMember.parent = to nesting functions CT/North East Sum of North East and South = 1 Geography 0 because it does not have a parent
  • 41. Parents on Two Dimensions
  • 42. Two Dimensions with Parent [Transactions]/ ([Transactions], [Geography].CurrentMember.Parent, [Products].CurrentMember.Parent )
  • 43. Ancestors on Two Dimensions
  • 44. Two Dims with Ancestor [Transactions]/ ([Transactions], Ancestor ([Geography].CurrentMember, [Geography].Generations(2) ), Ancestor ([Products].CurrentMember, [Products].Generations(2) ) )
  • 45. Part 3 Beyond Basics IIF CASE Rolling calculations
  • 46. IIF(Conditional test,True logic,False logic ) IIF( IsUDA([Measures].currentmember, “Expense”), [Prev Year] – [Curr Year], [Curr Year] – [Prev Year] ) IIF
  • 47. CASE When condition Then logic Else (optional) End CASE When IS([Time].Currentmember, [Qtr1]) Then [Mar] End Case
  • 48. PrevMember and NextMember Syntax [Member].PrevMember Example [Sales] = ( [Sales], [Year].CurrentMember.PrevMember ) * 1.10 Marketing Technologies Group | www.mtgny.com
  • 49. Lead and Lag Syntax member.Lag (index [,layertype ] [, hierarchy ] ) Example [Sales] = ( [Sales], [Year].CurrentMember.lag(2) ) * 1.10
  • 50. Rolling Calculations Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Prev Year 3 4 6 8 9 10 5 5 7 13 9 4 Curr Year 7 3 1 1 6 5 5 - - - - - One Time Dimension Two Time Dimensions
  • 51. Functions Used Avg ( set [,numeric_value_expression [,IncludeEmpty ] ]) Sum ( set [,numeric_value_expression ] ) LastPeriods(numeric_value_expression[,member[,hierarchy]] ) Count ( set [, IncludeEmpty] )
  • 52. Rolling Calculations Step by Step 1. Create a Simple Average() 2. Create a range with LastPeriods() 3. Make range relative with .CurrentMember
  • 53. Avg ( LastPeriods(6, Jun ) , Units) Rolling Average Example Avg ( {Jan : Jun } , Units) Avg ( LastPeriods(6, [Time].Currentmember ), Units)
  • 54. 2D Rolling Calcs Number of months needed from previous year changes each month “Count” the months available in the Currentmember year ● Count(LastPeriods(6,[Time].Currentmember) Subtract to get months needed from previous year ● 6 - Count(LastPeriods(6,[Time].Currentmember) Use the difference relative to Dec ● LastPeriods( 6 - Count(LastPeriods(6,[Time].CurrentMember)), Dec )
  • 55. 2D Rolling Calc Example Sum(LastPeriods(6,[Time].Currentmember),Units) Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Previous Year 4 4 8 1 1 8 4 9 9 5 5 4 Current Year 8 8 9 7 2 2 9 10 2 6 7 7 9 5 5 4 + Sum ( set [,numeric_value_expression ] ) Months NA This Yr , Last Year’s Units ), (Units,[Years].Currentmember.Prevmember) LastPeriods(6 - count(LastPeriods(6,[Time].Currentmember)) , Dec)
  • 56. Thank you for attending The End
  • 58. Levels and Generations Function form and property form Generations and Levels refers to a specific layer number Specific generation or level Dimension.Generations ( GenNum ) Dimension.Levels ( LevNum ) Marketing Technologies Group | www.mtgny.com
  • 59. A Set of Ancestors Ancestors ( member , layer | index ) e.g. Ancestors ( Jan , 2 ) Marketing Technologies Group | www.mtgny.com
  • 61. Example: Simple Assignments and Ratios Profit Pct Marketing Technologies Group | www.mtgny.com Marketing Technologies Group | www.mtgny.com Essbase Calc Language “Gross Profit” / “Net Sales”; MDX [Gross profit] / [Net Sales]
  • 62. Example: Inventory Balance Forward Marketing Technologies Group | www.mtgny.com Essbase Calc Language @Prior(Inventory) +”Inventory Change”; MDX ([Measures].[Inventory], [Year].CurrentMember.PrevMember ) + ( [Measures].[Inventory Change] )
  • 63. Example: Referring to Relatives Share of Region Marketing Technologies Group | www.mtgny.com Essbase Calc Units /@Ancestval(“Market Total”, 3, Units ); MDX [Units] / ( [Units], Ancestor([Market Total].CurrentMember, [Market Total].Generations(3) ) )
  • 64. Thank you Thanks for joining Please email me your comments: ● Your success level ● Speed of presentation ● Quality/Accuracy of documentation ● Effective/ineffective slides and presentations ● Email questions on content and solutions ● rmoore@topdownconsulting.com and/or monica.christie@camutogroup.com
  • 65. CrossJoin() Crossjoin() creates the Cartesian product of two sets Crossjoin( { Jan, Feb }, {[2006], [2007]} ) returns {(Jan,[2006]),(Jan,[2007]),(Feb,[2006]), (Feb, [2007])} Notes ● Only 2 sets at time –nest crossjoins for more than 2 ● Second set changes fastest Marketing Technologies Group | www.mtgny.com
  • 67. Layer (Reset layer) QTD YTD Gen5 Jan Jan Jan Gen5 Feb Jan+Feb Jan+Feb Gen5 Mar Jan+Feb+Mar Jan+Feb+Mar Gen4 Qtr1 Reset Gen5 Apr Apr Jan+Feb+Mar+Apr Gen5 May Apr+May Jan+Feb+Mar+Apr+May Gen5 Jun Apr+May+Jun Jan+Feb+Mar+Apr+May+Jun Gen4 Qtr2 Reset Gen3 1st Half Gen5 Jul Jul Jan+Feb+Mar+Apr+May+Jun+Jul Gen5 Aug Jul+Aug Jan+Feb+Mar+Apr+May+Jun+Jul+Aug Gen5 Sep Jul+Aug+Sep Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep Gen4 Qtr3 Reset Gen5 Oct Oct Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+Oct Gen5 Nov Oct+Nov Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+Oct+Nov Gen5 Dec Oct+Nov+Dec Jan+Feb+Mar+Apr+May+Jun+Jul+Aug+Sep+Oct+Nov+Dec Gen4 Qtr4 Reset Gen3 2nd Half Gen2 Year Total Reset Gen1 Time
  • 68. Periods to Date Year To Date Sum( {PeriodsToDate ([Time].Generations(2), [Time].CurrentMember ) } ) Quarter to Date Sum( {PeriodsToDate ([Time].Generations(4), [Time].CurrentMember ) } )
  • 69.
  • 70. Create a Simple Average Syntax: Avg ( set [,numeric_expression [,IncludeEmpty ] ]) Example: Avg ({Jan:Jun}, Units)
  • 71. LastPeriods() to Create a Range Syntax: LastPeriods ( numeric_expression [, member [, hierarchy ] ] ) Example: Avg ( LastPeriods( 6, Jun), Units) Marketing Technologies Group | www.mtgny.com
  • 72. .CurrentMember to Make the Range Relative Example: Avg ( LastPeriods (6, [Time].CurrentMember), Units) Marketing Technologies Group | www.mtgny.com
  • 73. Syntax Review #1 Select - From - Where query structure MemberName or [Member Name] [MemberName] or [Dim].[Member Name] { MemberName1, [Member Name2] } Marketing Technologies Group | www.mtgny.com
  • 74. Using Generation or Level Names
  • 75. Share of Ancestor [Transactions]/ ( [Transactions], Ancestor ( [Geography].CurrentMember, [Geography].Generations(2) ) ) Ancestor ( member , layer | index [, hierarchy ] )
  翻译: