180 likes | 319 Views
MDX Gotcha! s. … or how to keep your hair dark…. Your Speaker. Boyan Penev Microsoft MVP: SQL Server for 2011 Expertise SSAS PowerPivot SSRS SSIS e tc, etc, etc (you get the point ;) Blog: www.bp-msbi.com. Quick Agenda. MDX Problems
E N D
MDXGotcha!s …or how to keep your hair dark…
Your Speaker • Boyan Penev • Microsoft MVP: SQL Server for 2011 • Expertise • SSAS • PowerPivot • SSRS • SSIS • etc, etc, etc (you get the point ;) • Blog: www.bp-msbi.com
Quick Agenda • MDX Problems • Incorrect Data Models • Under-used SSAS functionality • Inefficient MDX • Detecting Problems • Demo (some examples)
MDX Problems (re: Data Model) Leaf-Level Calculations • SUM(DESCENDANTS(<member>,,LEAVES), <measure1>/<measure2>) • SCOPE(LEAVES(<dimension>); This = <measure1>/<measure2>; END SCOPE; • Alternatives • ETL, DB Views, DSV: <measure1>/<measure2> • Demo
MDX Problems (re: Data Model) Date Calculations • ParallelPeriod() • ClosingPeriod() • YTD(), QTD(), MTD() Common Causes • Incomplete Date Dimensions (gaps, missing members) • Wrong Structure (hierarchies, attrels) • Dimensions not marked as Time
ParallelPeriod(Quarter, Apr 08)= Mar 08 Closing Period(Q3 08) = Aug08
MDX Problems (re: SSAS Functionality) Semi-Additive Measures in EE • Replicating the same behaviour in MDX Many 2 Many Relationships • Performing SQL-style JOINs in MDX Measure Expressions • Writing them in MDX • Note that aggregations are not used with MEs
MDX Problems (re: Inefficient MDX) Using IIF instead of SCOPE (> importance in 2005) • IIF(a.CurrentMember Is <a.member>, NULL, <measure>)is the same (functionally) as:SCOPE(<a.member>); This = NULL;END SCOPE;
MDX Problems (re: Inefficient MDX) Set Operations • Filter(<d>.<h>.<l>, <d>.<h>.CurrentMember.MemberValue < 20110315) is equivalent to: {NULL:<d>.<h>.<l>.&[20110315]} • Demo
MDX Problems (re: Inefficient MDX) Using VBA/Excel Functions • VBA!Format() ~ FORMAT_STRING • VBA!DateAdd() = <d>.<h>.<l>.<m>.NextMember, or<d>.<h>.<l>.<m>.PrevMember, or<d>.<h>.<l>.<m>.Lag(n), or<d>.<h>.<l>.<m>.Lead(n) • VBA!DateDiff() ={<d>.<h>.<l>.<m>: <d>.<h>.<l>.<m>}.Count • Demo
MDX Problems (re: Inefficient MDX) • StrToSetand StrToMember • Use sparingly • LinkMember, LookupCube • Avoid at all costs • Filter • Often over-used, be cautious
Detecting Problems • Execution Time • SQL Server Profiler • Excessive number of data requests • Touching too many partitions and aggregations • Performance Monitor • Several SSAS MDX counters • Bulk mode evaluation nodes • Cell-by-Cell evaluation nodes • Number of cells evaluated • Memory/CPU Utilisation