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