SSAS and MDX

3,064 views

Published on

Carmen Faber SSAS sample development

  • Be the first to comment

SSAS and MDX

  1. 1. Carmen Faber MBA, OCP<br />Wharton, NJ<br />carmenfaber@gmail.com<br />Business Intelligence <br />Suite Developer<br />1<br />Is Business Intelligence in Your Business?<br />
  2. 2. Portfolio Overview<br />This portfolio contains selected examples <br />of my development skills using <br />Microsoft Business Intelligence <br />SSAS and Sample MDX using BIDS<br />SSAS using Microsoft Visual Studio page 3-20 MDX – Multi-Dimensional Queries <br />Cube Structure Various sample Queries - page 21-43 <br />Data Source View <br />Dimension Usage<br />Job Master Dimension Structure / Hierarchy <br />Sample SSAS Calculation<br />Calculation – Open Receivable Percent of Inventory<br />Calculation – Total Cost<br />Calculation - Overhead Percent of Total Cost<br />Calculation - Total Profit<br />Calculation - Profit Percent<br />Calculation - Job Increase<br />Calculation - Overhead Percent Increase<br />Sample SSAS KPIs<br />KPI Open Receivable<br />KPI Job Increase<br />KPI Profit Percent<br />KPI Overhead Percent Increase<br />KPI Profit Percent<br />Partitions<br />Perspective<br />Test using Browser<br />2<br />Is Business Intelligence in Your Business?<br />
  3. 3. SSAS Project All Works Cube (Measures/Fact and Dimension)<br />3<br />Is Business Intelligence in Your Business?<br />
  4. 4. SSAS Project Data Source View<br />4<br />Is Business Intelligence in Your Business?<br />
  5. 5. SSAS Project Dimension Usage<br />5<br />Is Business Intelligence in Your Business?<br />
  6. 6. SSAS Project – Job Master Dimension Structure / Hierarchy<br />6<br />Is Business Intelligence in Your Business?<br />
  7. 7. SSAS Project – Calculation – Open Receivable Percent of Inventory<br />CASE<br /> WHEN [Measures].[Invoice Amount] = 0<br /> THEN -1.<br /> ELSE<br />([Measures].[Invoice Amount]-[Measures].[Amount Received])/[Measures].[Invoice Amount]<br />END<br />7<br />Is Business Intelligence in Your Business?<br />
  8. 8. SSAS Project – Calculation – Total Cost<br />[Measures].[Total Overhead] + [Measures].[Total Material Cost]+ [Measures].[Total Labor Cost]<br />8<br />Is Business Intelligence in Your Business?<br />
  9. 9. SSAS Project – Overhead Percent of Total Cost<br />CASE<br /> WHEN [Measures].[Total Overhead] / [Measures].[TotalCost] = 0<br /> THEN 0<br /> ELSE<br />[Measures].[Total Overhead] / [Measures].[TotalCost]<br />END<br />9<br />Is Business Intelligence in Your Business?<br />
  10. 10. SSAS Project – Total Profit<br />[Measures].[Total Labor Profit] + [Measures].[Total Material Profit] +[Measures].[Additional Labor Profit]<br />10<br />Is Business Intelligence in Your Business?<br />
  11. 11. SSAS Project – Profit Percent<br />CASE<br /> WHEN [Measures].[TotalCost] = 0<br /> THEN &apos;100%&apos;<br /> ELSE<br />[Measures].[TotalProfit] / ([Measures].[TotalCost] +[Measures].[TotalProfit])<br />END<br />11<br />Is Business Intelligence in Your Business?<br />
  12. 12. SSAS Project – Job Increase<br />[Measures].[Job Summary Facts Count] -<br />([Measures].[Job Summary Facts Count] , ParallelPeriod ([Fy Qtr].[Fy Qtr], 1))<br />12<br />Is Business Intelligence in Your Business?<br />
  13. 13. SSAS Project – Overhead Percent Increase<br />CASE<br /> WHEN ([Measures].[Weekly Over Head] , ParallelPeriod ([Fy Qtr].[Fy Qtr], 1)) = 0 THEN 1<br /> ELSE<br />([Measures].[Weekly Over Head] -<br />([Measures].[Weekly Over Hea<br />d] , ParallelPeriod ([Fy Qtr].[Fy Qtr], 1)))<br />/([Measures].[Weekly Over Head] , ParallelPeriod ([Fy Qtr].[Fy Qtr], 1))<br />END<br />13<br />Is Business Intelligence in Your Business?<br />
  14. 14. SSAS Project – KPI Open Receivable<br />CASE <br /> WHEN KPIVALUE(&quot;KPIOpenReceivable&quot;) &lt;= KPIGOAL( &quot;KPIOpenReceivable&quot;) THEN 1<br /> WHEN KPIVALUE(&quot;KPIOpenReceivable&quot;)&gt;= KPIGOAL( &quot;KPIOpenReceivable&quot;) <br /> AND KPIVALUE(&quot;KPIOpenReceivable&quot;)&lt;= KPIGOAL( &quot;KPIOpenReceivable&quot;) * 2<br />THEN 0<br /> WHEN KPIVALUE(&quot;KPIOpenReceivable&quot;)&gt; KPIGOAL( &quot;KPIOpenReceivable&quot;)* 2 <br />THEN -1<br />END<br />14<br />Is Business Intelligence in Your Business?<br />
  15. 15. SSAS Project – KPI Job Increase<br />CASE <br /> WHEN KPIVALUE(&quot;KPIJobIncrease&quot;) &gt;= KPIGOAL( &quot;KPIJobIncrease&quot;) <br />THEN 1 <br /> WHEN KPIVALUE(&quot;KPIJobIncrease&quot;) &lt; KPIGOAL( &quot;KPIJobIncrease&quot;) <br />THEN -1<br />END<br />15<br />Is Business Intelligence in Your Business?<br />
  16. 16. SSAS Project – KPI Profit Percent<br />CASE <br /> WHEN KPIVALUE(&quot;KPIProfitPercent&quot;) &gt;<br /> KPIGOAL( &quot;KPIProfitPercent&quot;) <br />THEN 1<br /> WHEN KPIVALUE(&quot;KPIProfitPercent&quot;) &gt;= <br /> (KPIGOAL( &quot;KPIProfitPercent&quot;)/3)<br /> AND KPIVALUE(&quot;KPIProfitPercent&quot;) &lt;= <br /> KPIGOAL( &quot;KPIProfitPercent&quot;) <br />THEN 0<br /> WHEN KPIVALUE(&quot;KPIProfitPercent&quot;) &lt; <br /> (KPIGOAL( &quot;KPIProfitPercent&quot;)/ 3)<br />THEN -1<br />END<br />16<br />Is Business Intelligence in Your Business?<br />
  17. 17. SSAS Project – KPI Overhead Percent Increase<br />CASE <br /> WHEN KPIVALUE(&quot;KPIOverheadPercentIncrease&quot;) &lt;= <br /> KPIGOAL( &quot;KPIOverheadPercentIncrease&quot;) <br />THEN 1<br /> WHEN KPIVALUE(&quot;KPIOverheadPercentIncrease&quot;) &gt;= <br /> KPIGOAL( &quot;KPIOverheadPercentIncrease&quot;) <br /> AND KPIVALUE(&quot;KPIOverheadPercentIncrease&quot;) &lt;= <br /> KPIGOAL( &quot;KPIOverheadPercentIncrease&quot;) * 1.5<br />THEN 0<br /> WHEN KPIVALUE(&quot;KPIOverheadPercentIncrease&quot;) &gt; <br /> KPIGOAL( &quot;KPIOverheadPercentIncrease&quot;) * 1.5<br />THEN -1<br />END<br />17<br />Is Business Intelligence in Your Business?<br />
  18. 18. SSAS Project – Partitions<br />18<br />Is Business Intelligence in Your Business?<br />
  19. 19. SSAS Project – Perspective<br />19<br />Is Business Intelligence in Your Business?<br />
  20. 20. SSAS Project – Test using Browser<br />20<br />Is Business Intelligence in Your Business?<br />
  21. 21. MDX – Multi-Dimensional Queries<br />List Hours Worked and Total Labor for each employee for 2005, <br />-- along with the labor rate (Total labor / Hours worked). <br />WITH MEMBER[LaborRate] AS ([Total Labor] / [Hoursworked])<br />SELECT {[Hoursworked],[Total Labor], [LaborRate]} ON COLUMNS,<br />NON EMPTY( [Employees].[Full Name].members)<br />ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Year].[2005]<br />21<br />Is Business Intelligence in Your Business?<br />
  22. 22. MDX – Multi-Dimensional Queries<br />Retrieve total labor costs by County <br />SELECT [Measures].[Total Labor Cost]ON COLUMNS, <br />non empty([Job Master].[County Name].members) ON ROWS<br />FROM [All WorksCube]<br />22<br />Is Business Intelligence in Your Business?<br />
  23. 23. MDX – Multi-Dimensional Queries<br />Retrieve total labor costs by Division <br />SELECT [Measures].[Total Labor Cost]ON COLUMNS, <br />non empty([Job Master].[Division Name].members) ON ROWS<br />FROM [All WorksCube]<br />23<br />Is Business Intelligence in Your Business?<br />
  24. 24. MDX – Multi-Dimensional Queries<br />Retrieve total labor costs by Client Account grouping<br />SELECT [Measures].[Total Labor Cost]ON COLUMNS, <br />non empty([Job Master].[Client Groupings].members) ON ROWS<br />FROM [All WorksCube]<br />24<br />Is Business Intelligence in Your Business?<br />
  25. 25. MDX – Multi-Dimensional Queries<br />Retrieve 3 meatures…total labor cost, total material cost, and total overhead by client <br />SELECT {[Total Labor Cost], [Total Material Cost], [Total Overhead]}ON COLUMNS, <br />non empty([Job Master].[Client Name].MEMBERS)<br /> ON ROWS<br />FROM [All WorksCube]<br />25<br />Is Business Intelligence in Your Business?<br />
  26. 26. MDX – Multi-Dimensional Queries<br />Retrieve 3 meatures…total labor cost, total material cost, and total overhead by client <br />Do the same (retrieve 3 measures) and add a 4th measure,<br />-- a calculated measure, that adds all three costs <br />WITH MEMBER [AllCosts] AS <br />[Total Labor Cost]+ [Total Material Cost]+ [Total Overhead]<br />SELECT {[Total Labor Cost], [Total Material Cost], <br />[Total Overhead], [AllCosts]}ON COLUMNS, <br />non empty([Job Master].[Client Name].MEMBERS)<br /> ON ROWS<br />FROM [All WorksCube]<br />26<br />Is Business Intelligence in Your Business?<br />
  27. 27. MDX – Multi-Dimensional Queries<br />Retrieve and calculate the total costs, the total profit, and total profit %, for each individual job. The three are calculated as follows:<br />-- Total costs = total labor cost + total material cost + total overhead cost<br />-- Total profit = labor profit + material profit + additional labor overhead profit<br />-- Total profit % = (total profit / (total cost + total profit)) * 100<br />WITH MEMBER [TotalCosts] AS <br />[Total Labor Cost]+ [Total Material Cost]+ [Total Overhead]<br />MEMBER [TotalProfit] AS <br />[Total Labor Profit]+ [Total Material Profit]+ [Additional Labor Profit]<br />MEMBER [ProfitPct] AS <br />([TotalProfit] / ([TotalCosts]+[TotalProfit]) ) , format_string = &apos;percent‘<br />SELECT {[TotalCosts], [TotalProfit], [ProfitPct] }ON COLUMNS, <br />NON EMPTY ([Job Master].[Description].members)<br />HAVING [ProfitPct] &gt; 0 ON ROWS<br />FROM [All WorksCube]<br />27<br />Is Business Intelligence in Your Business?<br />
  28. 28. MDX – Multi-Dimensional Queries<br />Retrieve and calculate the total costs, the total profit, and total profit %, for each individual job. The three are calculated as follows:<br />-- Total costs = total labor cost + total material cost + total overhead cost<br />-- Total profit = labor profit + material profit + additional labor overhead profit<br />-- Total profit % = (total profit / (total cost + total profit)) * 100<br />Do the same thing as above, but group it by client <br />WITH MEMBER [TotalCosts] AS <br />[Total Labor Cost]+ [Total Material Cost]+ [Total Overhead]<br />MEMBER [TotalProfit] AS <br />[Total Labor Profit]+ [Total Material Profit]+ [Additional Labor Profit]<br />MEMBER [ProfitPct] AS <br />([TotalProfit] / ([TotalCosts]+[TotalProfit]) ) , format_string = &apos;percent&apos;<br />SELECT {[TotalCosts], [TotalProfit], [ProfitPct] }ON COLUMNS, <br />NON EMPTY ([Job Master].[Client Name].members) ON ROWS<br />FROM [All WorksCube]<br />28<br />Is Business Intelligence in Your Business?<br />
  29. 29. MDX – Multi-Dimensional Queries<br />Display a count of Jobs by Client in alphabetical order. Display NULLs as 0.<br />WITH MEMBER [JobSummaryFactsCount] as <br /> IIF ([MEASURES].[Job Summary Facts Count] &gt; 0, [MEASURES].[Job Summary Facts Count], 0)<br />SELECT [JobSummaryFactsCount] ON COLUMNS, <br /> [Job Master].[Client Name].MEMBERS ON ROWS<br />FROM [All WorksCube]<br />29<br />Is Business Intelligence in Your Business?<br />
  30. 30. MDX – Multi-Dimensional Queries<br />Retrieve all Clients with a Total Labor cost to date greater than 5,000, <br />and the word &apos;INC&apos; appears in the client name <br />SELECT [Total Labor Cost]ON COLUMNS, <br /> filter([Job Master].[Client Name].CHILDREN, <br />Instr([Job Master].[Client Name].CurrentMember.Name, &quot;INC&quot;) AND<br /> [Total Labor Cost]&gt; 5000 ) <br /> ON ROWS<br />FROM [All WorksCube]<br />30<br />Is Business Intelligence in Your Business?<br />
  31. 31. MDX – Multi-Dimensional Queries<br />List the jobs that make up the top 30% of total invoice amount <br />Select [Measures].[Invoice Amount] on columns,<br />TopPercent([Job Master].[Job Master].children, <br />30,[Measures].[Invoice Amount]) on Rows<br />from[All WorksCube]<br />31<br />Is Business Intelligence in Your Business?<br />
  32. 32. MDX – Multi-Dimensional Queries<br />Show Overhead by Overhead Category for Q3 and Q4 2005 (hint, use the FY Qtr as a dimension) <br />SELECT {[Fy Qtr].[2005 Q3], [Fy Qtr].&[2005 Q4]}<br />ON COLUMNS,<br />non empty ([Overhead].[Overhead].MEMBERS) ON ROWS<br />FROM [All WorksCube]<br />WHERE [Weekly Over Head]<br />32<br />Is Business Intelligence in Your Business?<br />
  33. 33. MDX – Multi-Dimensional Queries<br />Show Overhead by Overhead Category for Q3 and Q4 2005,<br />and also show the % of change between the two) <br />WITH member [ovheadCurrentPeriod] <br /> as ([Measures].[Weekly Over Head], [Fy Qtr].currentmember) <br />member [ovheadPriorPeriod] <br /> as ([Measures].[Weekly Over Head], [Fy Qtr].prevmember) <br />member [PctofCHG] AS <br />iif([ovheadPriorPeriod],<br /> ([ovheadCurrentPeriod] - [ovheadPriorPeriod])/ [ovheadPriorPeriod], <br /> null), format_string = &apos;0.00%;;;N/A&apos; <br />SELECT {[ovheadCurrentPeriod], [ovheadPriorPeriod], [PctofCHG] } <br />ON COLUMNS,<br />non empty([Overhead].[Description].MEMBERS) ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Qtr].[2005 Q4]<br />33<br />Is Business Intelligence in Your Business?<br />
  34. 34. MDX – Multi-Dimensional Queries<br />Show Overhead by Overhead Category for all of 2005, order by Overhead $$ amount descending <br />WITH SET [OrderOverhead] AS<br />ORDER([Overhead].[Overhead].MEMBERS, [Weekly Over Head], DESC)<br />SELECT [Weekly Over Head]<br />ON COLUMNS,<br />non empty ( [OrderOverhead]) <br />ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Year].[2005]<br />34<br />Is Business Intelligence in Your Business?<br />
  35. 35. MDX – Multi-Dimensional Queries<br />Show Material Purchase amounts by Material Type for 2005. <br />The result set should have 1 column for the purchase amounts for Fuel, Materials, and petty Cash <br />SELECT [Purchase Amount] ON COLUMNS,<br />[Material Types].[Description].members<br />ON ROWS<br />FROM [All WorksCube]<br />35<br />Is Business Intelligence in Your Business?<br />
  36. 36. MDX – Multi-Dimensional Queries<br />Show Material purchase amounts for 2005, broken out by Material Purchase type and client.<br />(for instance, Fuel for client A, B, C…Petty Cash for client A, B, C, etc.) <br />Display NULLs as $0.00<br />WITH MEMBER [PurchaseAmt] as <br /> IIF ([MEASURES].[Purchase Amount] &gt; 0, [Purchase Amount], 0), format_string = &apos;currency&apos;<br />SELECT [PurchaseAmt] ON COLUMNS,<br />([Material Types].[Description].children, [Client Name].children)<br />ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Year].[2005]<br />36<br />Is Business Intelligence in Your Business?<br />
  37. 37. MDX – Multi-Dimensional Queries<br />Show a list of total client material purchases for 2005, <br />in descending purchase amount order. The result set should show at the top which client required the most materials. <br />WITH SET [OrderClientPurchAmt] AS<br />order( [Client Name].children, [Purchase Amount], desc)<br />SELECT [Purchase Amount] ON COLUMNS,<br />non empty ( [OrderClientPurchAmt] )<br />ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Year].[2005]<br />37<br />Is Business Intelligence in Your Business?<br />
  38. 38. MDX – Multi-Dimensional Queries<br />-- Show jobs in order of purchase amount and then show the<br />-- breakdown in each job of material type (for instance, Job A, total purchase amount, amount for fuel, amount for materials, amount for petty cash, etc.) The general order should be by <br />-- total purchase amount, so that the top of the result set <br />-- shows the jobs that required the highest purchase amounts <br />WITH SET [OrderedJOB] AS <br />ORDER( [Job Master].[Job Master].CHILDREN, [Purchase Amount], desc) <br />MEMBER [PurchaseAmt] AS IIF ([Purchase Amount]&gt; 0, [Purchase Amount], 0), format_string = &apos;currency&apos;<br />SELECT [PurchaseAmt] ON COLUMNS,<br />([OrderedJOB], [Material Types].[Description].members)<br />ON ROWS<br />FROM [All WorksCube]<br />38<br />Is Business Intelligence in Your Business?<br />
  39. 39. MDX – Multi-Dimensional Queries<br />List Hours Worked and Total Labor for each employee for 2005, <br /> along with the labor rate (Total labor / Hours worked). <br />WITH MEMBER[LaborRate] AS ([Total Labor] / [Hoursworked])<br />SELECT {[Hoursworked],[Total Labor], [LaborRate]} ON COLUMNS,<br />NON EMPTY( [Employees].[Full Name].members)<br />ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Year].[2005] <br />39<br />Is Business Intelligence in Your Business?<br />
  40. 40. MDX – Multi-Dimensional Queries<br />List Hours Worked and Total Labor for each employee for 2005, <br /> along with the labor rate (Total labor / Hours worked). <br />-- sort the employees by labor rate descending, to see the employees with <br />-- the highest labor rate at the top. <br />WITH MEMBER[LaborRate] AS ([Total Labor] / [Hoursworked])<br />SELECT {[Hoursworked],[Total Labor], [LaborRate]} ON COLUMNS,<br />NON EMPTY( <br />ORDER ([Employees].[Full Name].members, [LaborRate], bDESC)<br />)<br />ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Year].[2005]<br />40<br />Is Business Intelligence in Your Business?<br />
  41. 41. MDX – Multi-Dimensional Queries<br />For 2005, show Total Hours worked, total labor dollars, and total labor rate<br />for contractors (employee flag is false) and employees (employee flag is true) <br />WITH MEMBER[LaborRate] AS ([Total Labor] / [Hoursworked])<br />SELECT {[Hoursworked],[Total Labor], [LaborRate]} ON COLUMNS,<br /> non empty ([Employees].[Employee Flag].members)<br />ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Year].[2005]<br />41<br />Is Business Intelligence in Your Business?<br />
  42. 42. MDX – Multi-Dimensional Queries<br />For 2005, show the job and the top three employees who worked the most hours. <br />-- Show the jobs in job order, and within the job show the employees in hours worked order <br />WITH SET [JobTop3emp] AS<br /> GENERATE( [Job Master].[Description].children ,<br />([Job Master].[Description].currentmember, topcount( [Employees].[Employees].children, 3, [Hoursworked]) ) <br /> )<br />SELECT [Hoursworked] ON COLUMNS,<br />non empty ( [JobTop3emp] )<br />ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Year].[2005]<br />42<br />Is Business Intelligence in Your Business?<br />
  43. 43. MDX – Multi-Dimensional Queries<br />Show All employees for 2005 Q4, and four periods ago, <br />-- for total hours worked in the Quarter <br />-- Display NULLs as 0<br />with member [HrsWrkParamWhereCLausewhichisQ42005] <br />as IIF (<br /> ([Fy Qtr].currentmember,[Measures].[Hoursworked] ) &gt; 0,<br /> ([Fy Qtr].currentmember,[Measures].[Hoursworked] ), 0)<br />member [HrsWrk4PeriodsAgo] <br /> as IIF (<br /> ([Measures].[Hoursworked] , ParallelPeriod ([Fy Qtr].[Fy Qtr], 4)) &gt; 0, <br /> ([Measures].[Hoursworked] , ParallelPeriod ([Fy Qtr].[Fy Qtr], 4)), 0)<br />SELECT { [HrsWrk4PeriodsAgo] ,<br />[HrsWrkParamWhereCLausewhichisQ42005]} ON COLUMNS,<br />[Employees].[Full Name].children ON ROWS<br />FROM [All WorksCube]<br />WHERE [Fy Qtr].[2005 Q4]<br />43<br />Is Business Intelligence in Your Business?<br />
  44. 44. Thank you for Your Time<br />I hope you enjoyed your few minutes of viewing what took intense months of training to accomplished<br />44<br />Is Business Intelligence in Your Business?<br />

×