Introduction to Solving Business Problems with MDX Robert Zare and Tom Conlon Program Managers...
-
Upload
paulina-stone -
Category
Documents
-
view
215 -
download
2
Transcript of Introduction to Solving Business Problems with MDX Robert Zare and Tom Conlon Program Managers...
Introduction to Solving Introduction to Solving Business Problems with MDXBusiness Problems with MDX
Robert Zare and Tom ConlonRobert Zare and Tom Conlon
Program ManagersProgram Managers
MicrosoftMicrosoft
AgendaAgenda
• MDX basicsMDX basics• Time series analysisTime series analysis• Multidimensional NavigationMultidimensional Navigation• Snapshot data analysisSnapshot data analysis
What is MDX?What is MDX?
• MDX is MDX is MMulti ulti DDimensional Eimensional EXXpressionspressions• MDX is the syntax for querying an Analysis MDX is the syntax for querying an Analysis
Services databaseServices database• MDX is part of the OLE DB for OLAP specMDX is part of the OLE DB for OLAP spec• MDX is the key for to utilizing the MDX is the key for to utilizing the
advanced analytical capabilities of advanced analytical capabilities of Analysis ServicesAnalysis Services
Comparison to SQLComparison to SQL
SQL ConstructSQL Construct OLAP constructOLAP construct
SELECT…SELECT… SELECT… SELECT… (MDX)(MDX)
FROMFROM FROM…FROM…(MDX)(MDX)
WHEREWHERE WHERE…WHERE…(MDX)(MDX)
CREATE…CREATE… DSO object modelDSO object model
DROP…DROP…
INSERT…INSERT…
DELETE…DELETE…
MDX basicsMDX basics
• MDX allows easy navigation in the multi MDX allows easy navigation in the multi dimensional spacedimensional space
• It “understands” the MD concepts of cube, It “understands” the MD concepts of cube, dimension, level, memberdimension, level, memberand celland cell
• It is used for It is used for – Queries – full statements (SELECT…FROM)Queries – full statements (SELECT…FROM)– Business modeling – definingBusiness modeling – defining
calculated members using MDX Expressions calculated members using MDX Expressions – – not a full statementnot a full statement
MDX Queries vs. MDX MDX Queries vs. MDX ExpressionsExpressions
• MDX QueriesMDX Queries– Full statements (SELECT…FROM)Full statements (SELECT…FROM)– Most often generated by end-user query tools Most often generated by end-user query tools
and applications such as Excel or Data and applications such as Excel or Data AnalyzerAnalyzer
– MDX Sample App deals in queriesMDX Sample App deals in queries• MDX Expressions MDX Expressions
– Partial MDX statements Partial MDX statements – Define an analytical object such as calculated Define an analytical object such as calculated
member, or named setmember, or named set– Return a single value (which may be a set)Return a single value (which may be a set)
MDX mythMDX myth
Fact: MDX is used everywhere:Fact: MDX is used everywhere: Calculated membersCalculated members Security settingsSecurity settings Custom member formulaCustom member formula Custom level formulaCustom level formula ActionsActions Named SetsNamed Sets Calculated CellsCalculated Cells
““Only developers need to know MDX”Only developers need to know MDX”
MDX constructsMDX constructs• Members: an item in a hierarchyMembers: an item in a hierarchy– [John Doe][John Doe]– [2001][2001]– [2001].[Q1].[Jan][2001].[Q1].[Jan]
• Tuple: an intersection of 2 or more membersTuple: an intersection of 2 or more members– ([Product].[Drink].[Beverages], [Customers].[USA])([Product].[Drink].[Beverages], [Customers].[USA])– ([Product].[Non-Consumable], [2001])([Product].[Non-Consumable], [2001])
• Sets: a group of tuples or membersSets: a group of tuples or members– {[John Doe], [Jane Doe]}{[John Doe], [Jane Doe]}– { ( [Non-Consumable], USA ), ( Beverages, Mexico ) }{ ( [Non-Consumable], USA ), ( Beverages, Mexico ) }– [2001].Children[2001].Children– TopCount(Store.[Store Name].Members, 10, Sales)TopCount(Store.[Store Name].Members, 10, Sales)
GroceriesGroceries
ClothingClothingAppliancesAppliances
SalesSales CostCostUnitsUnits
Every cell has a name...Every cell has a name...
19991999
20002000
20012001
19981998
19971997
MeasuresMeasures
Time
Time
Products
Products
GroceriesGroceries
ClothingClothingAppliancesAppliances
SalesSales CostCostUnitsUnits
(Products.Clothing, Measures.Units, Time.[2000])(Products.Clothing, Measures.Units, Time.[2000])
Every cell has a name...Every cell has a name...
19991999
20002000
20012001
19981998
19971997
MeasuresMeasures
Time
Time
Products
Products
GroceriesGroceries
ClothingClothingAppliancesAppliances
SalesSales CostCostUnitsUnits
(Products.Clothing, Measures.Units, Time.[2000])(Products.Clothing, Measures.Units, Time.[2000])
(Products.Clothing, Measures.Sales, Time.[1999])(Products.Clothing, Measures.Sales, Time.[1999])
Every cell has a name...Every cell has a name...
19991999
20002000
20012001
19981998
19971997
MeasuresMeasures
Time
Time
Products
Products
GroceriesGroceries
ClothingClothingAppliancesAppliances
SalesSales CostCostUnitsUnits
(Products.Clothing, Measures.Units, Time.[2000])(Products.Clothing, Measures.Units, Time.[2000])
(Products.Clothing, Measures.Sales, Time.[1999])(Products.Clothing, Measures.Sales, Time.[1999])
(Products.Groceries, Measures.Cost, Time.Year.[1997])(Products.Groceries, Measures.Cost, Time.Year.[1997])
Every cell has a name...Every cell has a name...
19991999
20002000
20012001
19981998
19971997
MeasuresMeasures
Time
Time
Products
Products
19991999
20002000
20012001
GroceriesGroceries
ClothingClothingAppliancesAppliances
SalesSales CostCost UnitsUnits
(Products.Clothing, Measures.Units, Time.[2000]) =(Products.Clothing, Measures.Units, Time.[2000]) =(Products.CurrentMember, (Products.CurrentMember,
Measures.CurrentMember, Measures.CurrentMember, Time.CurrentMember)Time.CurrentMember)
19981998
19971997
The current cell: CurrentMemberThe current cell: CurrentMember
20002000
ClothingClothing
SalesSales
??
Naming cells with relative Naming cells with relative references...references...
20002000
ClothingClothing
SalesSales
??
??
Naming cells with relative Naming cells with relative references...references...(Products.Clothing, Measures.Sales, Time.[2000].PrevMember)(Products.Clothing, Measures.Sales, Time.[2000].PrevMember)
20002000
ClothingClothing
SalesSales
??
??
??
Naming cells with relative Naming cells with relative references...references...(Products.Clothing, Measures.Sales, Time.[2000].PrevMember)(Products.Clothing, Measures.Sales, Time.[2000].PrevMember)
(Products.Clothing, Measures.Sales, Time.[2000].NextMember)(Products.Clothing, Measures.Sales, Time.[2000].NextMember)
(Products.Clothing, Measures.Sales.PrevMember, Time.[2000].Lag(3))(Products.Clothing, Measures.Sales.PrevMember, Time.[2000].Lag(3))
20002000
ClothingClothing
SalesSales
??
??
??
Naming cells with relative Naming cells with relative references...references...(Products.Clothing, Measures.Sales, Time.[2000].PrevMember)(Products.Clothing, Measures.Sales, Time.[2000].PrevMember)
(Products.Clothing, Measures.Sales, Time.[2000].NextMember)(Products.Clothing, Measures.Sales, Time.[2000].NextMember)
OROR
(Products.Clothing, (Products.Clothing, Measures.Sales.PrevMember,Measures.Sales.PrevMember,Time.[2000].Time.[2000].Lead(-3)Lead(-3)))
Calculated membersCalculated members
Calculated Calculated members add members add significant power to significant power to cubescubes
Pre-define complex Pre-define complex business logic (so business logic (so that user does not that user does not have to)have to)
Computed at run-Computed at run-timetime
AgendaAgenda• MDX basicsMDX basics• Time series analysisTime series analysis• Multidimensional NavigationMultidimensional Navigation• Snapshot data analysisSnapshot data analysis
1. How did Sales this period compare with Sales in 1. How did Sales this period compare with Sales in the previous period?the previous period?
YearYear QtrQtr MonMon SalesSales20002000 790790
Q1Q1 120120JanJan 3030FebFeb 4040MarMar 5050
Q2Q2 200200AprApr 6565MayMay 4545JunJun 9090
Q3Q3 185185JulJul 5555AugAug 6060SepSep 7070
Q4Q4 285285OctOct 8080NovNov 100100DecDec 105105
QtrQtr MonMon SalesSales DeltaDeltaQ2Q2 200200 8080
AprApr 6565 1515
MayMay 4545 -20-20
JunJun 9090 4545
1. How did Sales this period compare with Sales in 1. How did Sales this period compare with Sales in the previous period?the previous period?
(Time.CurrentMember, Measures.CurrentMember) =(Time.CurrentMember, Measures.CurrentMember) =
QtrQtr MonMon SalesSales DeltaDeltaQ2Q2 200200 8080
AprApr 6565 1515
MayMay 4545 -20-20
JunJun 9090 4545
1. How did Sales this period compare with Sales in 1. How did Sales this period compare with Sales in the previous period?the previous period?
(Time.CurrentMember, Measures.CurrentMember) =(Time.CurrentMember, Measures.CurrentMember) =
(Time.CurrentMember, Measures.Sales) -(Time.CurrentMember, Measures.Sales) -
QtrQtr MonMon SalesSales DeltaDeltaQ2Q2 200200 8080
AprApr 6565 1515
MayMay 4545 -20-20
JunJun 9090 4545
(Time.CurrentMember.PrevMember, Measures.Sales)(Time.CurrentMember.PrevMember, Measures.Sales)
1. How did Sales this period compare with Sales in 1. How did Sales this period compare with Sales in the previous period?the previous period?
(Time.CurrentMember, Measures.CurrentMember) =(Time.CurrentMember, Measures.CurrentMember) =
(Time.CurrentMember, Measures.Sales) (Time.CurrentMember, Measures.Sales) --
Calculated measure: [Sales Growth]Calculated measure: [Sales Growth]
2. How did Sales in the current period compare with Sales in the same 2. How did Sales in the current period compare with Sales in the same period last year?period last year?
YearYear QtrQtr MonMon SalesSales20002000 790790
Q1Q1 120120JanJan 3030FebFeb 4040MarMar 5050
Q4Q4 285285OctOct 8080NovNov 100100DecDec 105105
20012001 850850 Q1Q1 170170
JanJan 5050FebFeb 5555MarMar 6565
Q4Q4 275275OctOct 9090NovNov 100100DecDec 8585
YearYear QtrQtr MonMon SalesSales Annual DeltaAnnual Delta20002000 790790
Q1Q1 120120JanJan 3030FebFeb 4040MarMar 5050
20012001 850850 Q1Q1 170170
JanJan 5050 2020FebFeb 5555MarMar 6565
2. How did Sales in the current period compare with Sales in the 2. How did Sales in the current period compare with Sales in the same period last year?same period last year?
(Time.CurrentMember, Measures.Sales)-
(Time.CurrentMember.Lag(12), Measures.Sales)
YearYear QtrQtr MonMon SalesSales Annual DeltaAnnual Delta20002000 790790
Q1Q1 120120JanJan 3030FebFeb 4040MarMar 5050
20012001 850850 Q1Q1 170170
JanJan 5050 2020FebFeb 5555MarMar 6565
2. How did Sales in the current period compare with Sales in the 2. How did Sales in the current period compare with Sales in the same period last year?same period last year?
(ParallelPeriod(Year,1,Time.CurrentMember), Measures.Sales)
(Time.CurrentMember.Lag(12), Measures.Sales)
(Time.CurrentMember, Measures.Sales)-
Calculated measure: [Sales Growth Y/Y]Calculated measure: [Sales Growth Y/Y]
3. What have my sales been since the beginning of 3. What have my sales been since the beginning of the year?the year?
YearYear QtrQtr MonMon SalesSales20002000 790790
Q1Q1 120120JanJan 3030FebFeb 4040MarMar 5050
Q2Q2 200200AprApr 6565MayMay 4545JunJun 9090
Q3Q3 185185JulJul 5555AugAug 6060SepSep 7070
Q4Q4 285285OctOct 8080NovNov 100100DecDec 105105
Time.Mar,Measures.Sales ...Time.Mar,Measures.Sales ...
Time.Jan,Measures.SalesTime.Jan,Measures.Sales ++Time.Feb,Measures.SalesTime.Feb,Measures.Sales ++
3. What have Sales been since the beginning of 3. What have Sales been since the beginning of the year?the year?
YearYear QtrQtr MonMon SalesSales YTDYTD20002000 790790
Q1Q1 120120 120120
JanJan 3030 3030
FebFeb 4040 7070
MarMar 5050 120120
Time.Mar,Measures.SalesTime.Mar,Measures.Sales
Time.Jan,Measures.SalesTime.Jan,Measures.Sales ++Time.Feb,Measures.SalesTime.Feb,Measures.Sales ++
3. What have Sales been since the beginning of 3. What have Sales been since the beginning of the year?the year?
==Sum(YTD(Time.CurrentMember), Sales)Sum(YTD(Time.CurrentMember), Sales)
YearYear QtrQtr MonMon SalesSales YTDYTD20002000 790790
Q1Q1 120120 120120
JanJan 3030 3030
FebFeb 4040 7070
MarMar 5050 120120
Calculated measure: [YTD Sales]Calculated measure: [YTD Sales]
AgendaAgenda• MDX basicsMDX basics• Time series analysisTime series analysis• Multidimensional NavigationMultidimensional Navigation• Snapshot data analysisSnapshot data analysis
Navigating the hierarchyNavigating the hierarchy(The Family Tree)(The Family Tree)
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A ll
ParentsParents
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A llTime.[2000].ParentTime.[2000].Parent
ParentsParents
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A llTime.[2000].ParentTime.[2000].Parent Time.[2001].ParentTime.[2001].Parent
ParentsParents
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A ll
Time.[2000].FirstChildTime.[2000].FirstChild
ChildrenChildren
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A ll
Time.[2000].FirstChildTime.[2000].FirstChild
ChildrenChildren
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A ll
Time.[2000].ChildrenTime.[2000].Children
ChildrenChildren
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A ll
Descendants( Time.Descendants( Time.[2000], Quarter) [2000], Quarter)
Descendants Descendants
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A ll
Descendants( Time.[2000], Month) Descendants( Time.[2000], Month)
Descendants Descendants
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A ll
Descendants(Time.[2000].[Jan], Descendants(Time.[2000].[Jan], Month) Month)
Descendants Descendants
Jan F eb M a r
Q 1 Q 2 Q 3
O c t N o v D e c
Q 4
2 000
Q 1 Q 2 Q 3 Q 4
2 001
A ll
Descendants(Time.[2000].[Jan], Descendants(Time.[2000].[Jan], Month) Month)
Descendants Descendants
AgendaAgenda• MDX basicsMDX basics• Time series analysisTime series analysis• Multidimensional NavigationMultidimensional Navigation• Snapshot data analysisSnapshot data analysis
The Inventory ProblemThe Inventory Problem
• A set of inventory snapshots over timeA set of inventory snapshots over time– DimensionsDimensions• Products: (All), Family, Category, NameProducts: (All), Family, Category, Name• Warehouses: (All), WarehouseWarehouses: (All), Warehouse• Time: Year, Quarter, MonthTime: Year, Quarter, Month• Store: (All), Country, City, StoreStore: (All), Country, City, Store
– MeasuresMeasures• Quantity [default aggregation=sum]Quantity [default aggregation=sum]
– The problem:The problem:• Measures are not additive over timeMeasures are not additive over time
The inventory problem: Semi-additive measuresThe inventory problem: Semi-additive measures
YearYear QtrQtr MonthMonth QuantityQuantity20002000 790790
Q1Q1 120120JanJan 3030FebFeb 4040MarMar 5050
Q2Q2 200200AprApr 6565MayMay 4545JunJun 9090
Q3Q3 185185JulJul 5555AugAug 6060SepSep 7070
Q4Q4 285285OctOct 8080NovNov 100100DecDec 105105
Problem: Problem: Quantity is not Quantity is not additive over additive over
timetime
Business solutions…Business solutions…
1.1. Average quantities in each time periodAverage quantities in each time period
2.2. Opening and closing balances for each Opening and closing balances for each time periodtime period
3.3. Minimum and maximum inventory levels in Minimum and maximum inventory levels in a time perioda time period
1. Average over time1. Average over time
1.1. Sum of quantities over all months in the Sum of quantities over all months in the period, divided by the number of months in period, divided by the number of months in the periodthe period
2.2. Sum(Sum( months in the period months in the period , , Quantity) / Count(Quantity) / Count( months in the months in the period period ))
3.3. Sum(Descendants( Time.CurrentMemSum(Descendants( Time.CurrentMember,[Month]), Quantity) / ber,[Month]), Quantity) / Count(Descendants( Time.CurrentMCount(Descendants( Time.CurrentMember,[Month]))ember,[Month]))
4.4. AvgAvg(( Descendants( Time.CurrentMe Descendants( Time.CurrentMember,[Month]), Quantitymber,[Month]), Quantity))
Calculated measure: [Average balance]Calculated measure: [Average balance]
2. Closing period inventory value… 2. Closing period inventory value…
YearYear QtrQtr MonthMonth QtyQty CalcCalc20002000 790790 105105
Q1Q1 120120 5050JanJan 3030 3030FebFeb 4040 4040MarMar 5050 5050
Q2Q2 200200 9090AprApr 6565 6565MayMay 4545 4545JunJun 9090 9090
Q3Q3 185185 7070JulJul 5555 5555AugAug 6060 6060SepSep 7070 7070
Q4Q4 285285 105105OctOct 8080 8080NovNov 100100 100100DecDec 105105 105105
2. Closing balance2. Closing balance
1.1. Quantity of the last month in the periodQuantity of the last month in the period
2.2. Quantity of the last item inQuantity of the last item in((Descendants(Time.CurrentMember, Descendants(Time.CurrentMember, [Month][Month]))
3.3. ((TailTail( ( Descendants( Time.CurrentMDescendants( Time.CurrentMember, [Month]ember, [Month])), 1), , 1), Measures.QuantityMeasures.Quantity))
4.4. ((ClosingPeriod([Month], ClosingPeriod([Month], Time.CurrentMember),Time.CurrentMember), Measures.QuantityMeasures.Quantity))
Calculated measure: [Closing Balance]Calculated measure: [Closing Balance]
3. Maximum Quantity During the 3. Maximum Quantity During the PeriodPeriod
• We want the Maximum monthly inventory We want the Maximum monthly inventory value for each periodvalue for each period
• MaxMax(( Descendants( Time.CurrentMember Descendants( Time.CurrentMember, Month), Measures.Quantity , Month), Measures.Quantity ))– Why did we calculate using Descendants(…, Why did we calculate using Descendants(…,
Month)? Why not use the Children function?Month)? Why not use the Children function?
Calculated measure: [Maximum Quantity]Calculated measure: [Maximum Quantity]
SummarySummary
• MDX is everywhereMDX is everywhere
• Calculated members are the most common Calculated members are the most common application of MDX in cube modelingapplication of MDX in cube modeling
• Understand the fundamental concepts: Understand the fundamental concepts: CurrentMemberCurrentMember, , .Parent.Parent, , .Children.Children, , DescendantsDescendants, etc. as these are the building , etc. as these are the building blocks for many expressionsblocks for many expressions
More InformationMore Information
• BooksBooks– Step by Step Analysis ServicesStep by Step Analysis Services
• JacobsenJacobsen
– Microsoft OLAP SolutionsMicrosoft OLAP Solutions• Thomsen, Spofford, ChaseThomsen, Spofford, Chase
– MDX SolutionsMDX Solutions• SpoffordSpofford
• OnlineOnline– Public NewsgroupPublic Newsgroup
• Microsoft.public.sqlserver.olapMicrosoft.public.sqlserver.olap
– MSN CommunityMSN Community• http://groups.msn.com/http://groups.msn.com/
MicrosoftOLAPServicesUsersCommunity/_homepage.msnw?MicrosoftOLAPServicesUsersCommunity/_homepage.msnw?pgmarket=en-uspgmarket=en-us
– Microsoft.comMicrosoft.com• http://microsoft.com/sql/evaluation/bi/default.asphttp://microsoft.com/sql/evaluation/bi/default.asp
Don’t forget to complete the Don’t forget to complete the on-line Session Feedback form on-line Session Feedback form on the Attendee Web siteon the Attendee Web site
https://web.mseventseurope.com/teched/https://web.mseventseurope.com/teched/