590 likes | 696 Views
Introduction to Solving Business Problems with MDX. Robert Zare and Tom Conlon Program Managers Microsoft. Agenda. MDX basics Time series analysis Multidimensional Navigation Snapshot data analysis. What is MDX?. MDX is M ulti D imensional E X pressions
E N D
Introduction to Solving Business Problems with MDX Robert Zare and Tom Conlon Program Managers Microsoft
Agenda • MDX basics • Time series analysis • Multidimensional Navigation • Snapshot data analysis
What is MDX? • MDX is Multi Dimensional EXpressions • MDX is the syntax for querying an Analysis Services database • MDX is part of the OLE DB for OLAP spec • MDX is the key for to utilizing the advanced analytical capabilities of Analysis Services
MDX basics • MDX allows easy navigation in the multi dimensional space • It “understands” the MD concepts of cube, dimension, level, memberand cell • It is used for • Queries – full statements (SELECT…FROM) • Business modeling – definingcalculated members using MDX Expressions – not a full statement
MDX Queries vs. MDX Expressions • MDX Queries • Full statements (SELECT…FROM) • Most often generated by end-user query tools and applications such as Excel or Data Analyzer • MDX Sample App deals in queries • MDX Expressions • Partial MDX statements • Define an analytical object such as calculated member, or named set • Return a single value (which may be a set)
MDX myth “Only developers need to know MDX” • Fact: MDX is used everywhere: • Calculated members • Security settings • Custom member formula • Custom level formula • Actions • Named Sets • Calculated Cells
MDX constructs • Members: an item in a hierarchy • [John Doe] • [2001] • [2001].[Q1].[Jan] • Tuple: an intersection of 2 or more members • ([Product].[Drink].[Beverages], [Customers].[USA]) • ([Product].[Non-Consumable], [2001]) • Sets: a group of tuples or members • {[John Doe], [Jane Doe]} • { ( [Non-Consumable], USA ), ( Beverages, Mexico ) } • [2001].Children • TopCount(Store.[Store Name].Members, 10, Sales)
Every cell has a name... Groceries Products Appliances Clothing 1997 1998 1999 Time 2000 2001 Measures Sales Cost Units
Every cell has a name... (Products.Clothing, Measures.Units, Time.[2000]) Groceries Products Appliances Clothing 1997 1998 1999 Time 2000 2001 Measures Sales Cost Units
Every cell has a name... (Products.Clothing, Measures.Units, Time.[2000]) (Products.Clothing, Measures.Sales, Time.[1999]) Groceries Products Appliances Clothing 1997 1998 1999 Time 2000 2001 Measures Sales Cost Units
Every cell has a name... (Products.Clothing, Measures.Units, Time.[2000]) (Products.Clothing, Measures.Sales, Time.[1999]) (Products.Groceries, Measures.Cost, Time.Year.[1997]) Groceries Products Appliances Clothing 1997 1998 1999 Time 2000 2001 Measures Sales Cost Units
The current cell: CurrentMember (Products.Clothing, Measures.Units, Time.[2000]) = (Products.CurrentMember, Measures.CurrentMember, Time.CurrentMember) Groceries Appliances Clothing 1997 1998 1999 2000 2001 Sales Cost Units
Naming cells with relative references... Clothing ? 2000 Sales
Naming cells with relative references... (Products.Clothing, Measures.Sales, Time.[2000].PrevMember) Clothing ? 2000 ? Sales
? Naming cells with relative references... (Products.Clothing, Measures.Sales, Time.[2000].PrevMember) (Products.Clothing, Measures.Sales, Time.[2000].NextMember) Clothing ? 2000 ? Sales
? Naming cells with relative references... (Products.Clothing, Measures.Sales, Time.[2000].PrevMember) (Products.Clothing, Measures.Sales, Time.[2000].NextMember) (Products.Clothing, Measures.Sales.PrevMember, Time.[2000].Lag(3)) OR (Products.Clothing, Measures.Sales.PrevMember, Time.[2000].Lead(-3)) Clothing ? 2000 ? Sales
Calculated members • Calculated members add significant power to cubes • Pre-define complex business logic (so that user does not have to) • Computed at run-time
Agenda • MDX basics • Time series analysis • Multidimensional Navigation • Snapshot data analysis
1. How did Sales this period compare with Sales in the previous period?
1. How did Sales this period compare with Sales in the previous period? (Time.CurrentMember, Measures.CurrentMember) =
1. How did Sales this period compare with Sales in the previous period? (Time.CurrentMember, Measures.CurrentMember) = (Time.CurrentMember, Measures.Sales) -
1. How did Sales this period compare with Sales in the previous period? (Time.CurrentMember, Measures.CurrentMember) = (Time.CurrentMember, Measures.Sales) - (Time.CurrentMember.PrevMember, Measures.Sales)
2. How did Sales in the current period compare with Sales in the same period last year?
(Time.CurrentMember, Measures.Sales)- (Time.CurrentMember.Lag(12), Measures.Sales) 2. How did Sales in the current period compare with Sales in the same period last year?
2. How did Sales in the current period compare with Sales in the same period last year? (Time.CurrentMember, Measures.Sales)- No! (Time.CurrentMember.Lag(12), Measures.Sales) (ParallelPeriod(Year,1,Time.CurrentMember), Measures.Sales)
+ Time.Feb,Measures.Sales 3. What have Sales been since the beginning of the year? + Time.Jan,Measures.Sales Time.Mar,Measures.Sales ...
+ Time.Feb,Measures.Sales Sum(YTD(Time.CurrentMember), Sales) 3. What have Sales been since the beginning of the year? + Time.Jan,Measures.Sales NO! = Time.Mar,Measures.Sales
Agenda • MDX basics • Time series analysis • Multidimensional Navigation • Snapshot data analysis
Parents Time.[2000].Parent
Parents Time.[2001].Parent Time.[2000].Parent
Children Time.[2000].FirstChild
Children Time.[2000].FirstChild
Children Time.[2000].Children
Descendants Descendants( Time.[2000], Quarter)
Descendants Descendants( Time.[2000], Month)
Descendants Descendants(Time.[2000].[Jan], Month)
Descendants Descendants(Time.[2000].[Jan], Month)
Agenda • MDX basics • Time series analysis • Multidimensional Navigation • Snapshot data analysis
The Inventory Problem • A set of inventory snapshots over time • Dimensions • Products: (All), Family, Category, Name • Warehouses: (All), Warehouse • Time: Year, Quarter, Month • Store: (All), Country, City, Store • Measures • Quantity [default aggregation=sum] • The problem: • Measures are not additive over time
The inventory problem: Semi-additive measures Problem: Quantity is not additive over time
Business solutions… • Average quantities in each time period • Opening and closing balances for each time period • Minimum and maximum inventory levels in a time period
1. Average over time • Sum of quantities over all months in the period, divided by the number of months in the period • Sum( months in the period , Quantity) / Count( months in the period ) • Sum(Descendants( Time.CurrentMember,[Month]), Quantity) / Count(Descendants( Time.CurrentMember,[Month])) • Avg( Descendants( Time.CurrentMember,[Month]), Quantity)