40
Solving Business Solving Business Problems in OLAP Problems in OLAP Services Using MDX Services Using MDX - Part II - Part II Amir Netz – Dev Manager & Amir Netz – Dev Manager & Architect Architect Ariel Netz – Program Manager Ariel Netz – Program Manager SQL Server OLAP Services SQL Server OLAP Services Microsoft Corporation Microsoft Corporation

Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Embed Size (px)

Citation preview

Page 1: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Solving Business Problems Solving Business Problems in OLAP Services Using in OLAP Services Using MDX MDX - Part II- Part II

Amir Netz – Dev Manager & ArchitectAmir Netz – Dev Manager & ArchitectAriel Netz – Program ManagerAriel Netz – Program Manager

SQL Server OLAP ServicesSQL Server OLAP ServicesMicrosoft CorporationMicrosoft Corporation

Page 2: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Yes,Yes,We Are Brothers.We Are Brothers.

Still

Page 3: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

AgendaAgenda Exception floatingException floating Market basket analysisMarket basket analysis Working with virtual cubesWorking with virtual cubes Currency conversionCurrency conversion Using UDF in MDXUsing UDF in MDX

Page 4: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Knowing MDXKnowing MDX

Functionality Functionality

KnowledgeKnowledge RequiredRequired

Part I

Page 5: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

For Each CurrentMember is the set:

Yes

No

CustomerCustomer Sales Sales (Printer)(Printer)

AmirAmir 150150

ArielAriel 4040

BillBill 7070

CoreyCorey 6565

Filter(Customers.Members,(Sales,Printers)>50)

{Amir,Ariel,Bill,Corey}

(Amir,Sales,Printer)>50IF

Amir

Filtering Sets

Page 6: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

For Each CurrentMember is the set:

Yes

No

CustomerCustomer Sales Sales (Printer)(Printer)

AmirAmir 150150

ArielAriel 4040

BillBill 7070

CoreyCorey 6565

Filter(Customers.Members,(Sales,Printers)>50)

{Amir,Ariel,Bill,Corey}

(Ariel,Sales,Printer)>50IF

Amir

Page 7: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

For Each CurrentMember is the set:

Yes

No

CustomerCustomer Sales Sales (Printer)(Printer)

AmirAmir 150150

ArielAriel 4040

BillBill 7070

CoreyCorey 6565

Filter(Customers.Members,(Sales,Printers)>50)

{Amir,Ariel,Bill,Corey}

(Bill,Sales,Printer)>50IF

AmirBill

Page 8: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

For Each CurrentMember is the set:

Yes

No

CustomerCustomer Sales Sales (Printer)(Printer)

AmirAmir 150150

ArielAriel 4040

BillBill 7070

CoreyCorey 6565

Filter(Customers.Members,(Sales,Printers)>50)

{Amir,Ariel,Bill,Corey}

(Corey,Sales,Printer)>50IF

AmirBillCorey

Page 9: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

CustomerCustomer Sales Sales (Printer)(Printer)

AmirAmir 150150

ArielAriel 4040

BillBill 7070

CoreyCorey 6565

Filter(Customers.Members,(Sales,Printers)>50)

{Amir,Bill,Corey}

Filter({Amir,Ariel,Bill,Corey},(Sales,Printers)>50)

Amir Netz:

Demo of filter – show set before and after

Amir Netz:

Demo of filter – show set before and after

Page 10: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Exception FloatingException Floating

Possible answer: 51% of the “Food” products sold

in 1998 did less then in 1997

For each product group find the the percentage For each product group find the the percentage

of the group’s products that had their sales of the group’s products that had their sales

decreased from the previous time perioddecreased from the previous time period

  Product GroupProduct Group   % Dropped% Dropped

FoodFood 51%51%DrinkDrink 27%27%Non-Consumable.Non-Consumable. 22%22%

Page 11: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Business Problem:Business Problem:

For each product group find the the For each product group find the the percentage of the group’s products that had percentage of the group’s products that had their sales decreased from the previous time their sales decreased from the previous time periodperiod

The number of products contained in the group

The number of products contained in the group that had their sales dropped from the previous time period

Page 12: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Phase I:Phase I:

M e at S . D ish C h ee se

D e li M e at

C a n dy C . B ar P o p C o rn

S n a cks

F o od

A lco h o lic S o ft D a iry

D rin k

A ll

The number of products contained in the current group

Count( products contained in the current group)

Count(Descendants(current group, [Product Name]))

Count(Descendants( Products.CurrentMember, [Product Name]))

Amir Netz:

Demo phase 1

Amir Netz:

Demo phase 1

Page 13: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Phase IIPhase II

The number of products contained in the current group that had their sales dropped from the previous time period

Count( products contained in the current group that had their sales dropped from the previous time period)

Count(Filter( products contained in the current group, sales < sales of the previous time period)

Count(Filter( Descendants( Products.CurrentMember, [Product Name]),

sales < sales of the previous time period)

Page 14: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Phase II - ContinuePhase II - Continue

Count(Filter( Descendants( Products.CurrentMember, [Product Name]),

([Sales],Time.CurrentMember)<([Sales],Time.CurrentMember.PrevMember)

Amir Netz:

Demo phase 2

Amir Netz:

Demo phase 2

Page 15: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Putting It All Together…Putting It All Together…

Count(Descendants( Products.CurrentMember, [Product Name]))

/Count(Filter( Descendants(

Products.CurrentMember, [Product Name]), ([Sales],Time.CurrentMember)<([Sales],Time.CurrentMember.PrevMember)

Gee…

Amir Netz:

demo

Amir Netz:

demo

Page 16: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Guided Drill DownGuided Drill Down

“There are so many numbers in my cube, can I have the system highlight the “interesting” numbers?”

Concept:Have the system guide the user to look at the “interesting” numbers. Guidance is given in the format of a textual massage.

Business Problem:

% Drop% Drop GuideGuide

Product GroupProduct Group 50%50% Drill HereDrill Here

FoodFood 51%51% Drill HereDrill Here

DrinkDrink 27%27%

NonNon

Consumable Consumable

22%22%

Page 17: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

IIF(Measures.[% Dropped] >0.5,”Drill Here”,” ”)

Just like Exception Floating + one “IIF”Just like Exception Floating + one “IIF”

Amir Netz:

demo

Amir Netz:

demo

Page 18: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Distinct Count In The OLAP Space.Distinct Count In The OLAP Space.Business Problem:Sales Manager wants to know: “How many customers are buying Computers? ““How many active customers do I have?”

SalesSales Number of Number of CustomersCustomers

All productsAll products 80008000 200200 HardwareHardware 33003300 8080 ComputersComputers 20002000 7070 MonitorsMonitors 800800 6060 PrintersPrinters 500500 3030SoftwareSoftware 47004700 150150 HomeHome 15001500 100100 BusinessBusiness 25002500 100100 GamesGames 700700 8080

Page 19: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Distinct Count is not a CountDistinct Count is not a Count

First thing to know about Distinct Count :

Page 20: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Count( Filter (Customers.[Name].Members, Sales> 0))

Count( Filter (Descendants( Customers.CurrentMember, Customers.[Name]), Sales> 0))

Business Problem:Business Problem::“How many different customers had sales for the :“How many different customers had sales for the current product/time/geography/promotion…?”current product/time/geography/promotion…?”

Number of customers that had salesCount( customers that had sales)Count( Filter (customers , Sales of current product/time/geo…> 0))Count( Filter (customers , Sales > 0))

Amir Netz:

Demo with bug – discover the bug during demo and fix

Amir Netz:

Demo with bug – discover the bug during demo and fix

Page 21: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Market Basket Analysis Market Basket Analysis

SalesSales Number of Number of CustomersCustomers

Number Of Number Of Customers Which Customers Which

AlsoAlso Bought Bought ComputerComputer

All productsAll products 80008000 200200 3030HardwareHardware 33003300 8080 3030 PrintersPrinters 20002000 7070 2020 MonitorsMonitors 800800 6060 2525 ComputersComputers 500500 3030 3030SoftwareSoftware 47004700 150150 1515 HomeHome 15001500 100100 77 BusinessBusiness 25002500 100100 1010 GamesGames 700700 8080 55

Business Problem:Sales Manager wants to know: “It will be very interesting to know how many of my customers bought both product X and a computer. Maybe a bundle is in place?”

Page 22: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Market Basket Analysis Market Basket Analysis

PrinterPrinter ComputersComputers

WAWA Total WATotal WA

SeattleSeattle Total SeattleTotal Seattle 190190 2020

AmirAmir 150150 2020

ArielAriel 4040

TacomaTacoma Total TacomaTotal Tacoma 255255 140140

BillBill 7070 8080

CoreyCorey 6565 6060

SueSue 120120

Page 23: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Market Basket Analysis Market Basket Analysis

PrinterPrinter ComputersComputers Yes/NoYes/No

WAWA Total WATotal WA

SeattleSeattle Total SeattleTotal Seattle 190190 2020

AmirAmir 150150 2020

ArielAriel 4040

TacomaTacoma Total TacomaTotal Tacoma 255255 140140

BillBill 7070 8080

CoreyCorey 6565 6060

SueSue 120120

Page 24: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Market Basket Analysis Market Basket Analysis

PrinterPrinter ComputersComputers Yes/NoYes/No

WAWA Total WATotal WA

SeattleSeattle Total SeattleTotal Seattle 190190 2020

AmirAmir 150150 2020

ArielAriel 4040

TacomaTacoma Total TacomaTotal Tacoma 255255 140140

BillBill 7070 8080

CoreyCorey 6565 6060

SueSue 120120

11

00

11

11

00

11

22

33XX

Page 25: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Market Basket Analysis Market Basket Analysis

PrintPrinterer

CompuComputersters

Yes/Yes/NoNo

WWAA

Total WATotal WA

SeatSeattletle

Total Total SeattleSeattle

190190 2020

AmirAmir 150150 2020 11

ArielAriel 4040

TacTacomaoma

Total Total TacomaTacoma

255255 140140

BillBill 7070 8080 11

CoreyCorey 6565 6060 11

SueSue 120120

Concept:If a customer bought a Printer and a Computer, “flag” the customer with the value of “1”, then sum all the “1” to get a final count.

Count for each product the customers who bought it together with a Computer)

Sum(Descendents(Customers.CurrentMember,Customer.Name), IIf((Sales,Products.CurrentMember)>0 AND (Sales,Computers)>0 ,1,0))

Sum(Customers in the current region, IIf( Bought both the current product and a Computer, 1,0))Sum(Descendents(Customers.CurrentMember,Customer.Name), IIf(Bought current product AND a Computer,1,0))

Amir Netz:

demo

Amir Netz:

demo

Page 26: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Market Basket Analysis Market Basket Analysis PrintPrinterer

CompuComputersters

Yes/Yes/NoNo

WWAA

Total WATotal WA

SeatSeattletle

Total Total SeattleSeattle

190190 2020

AmirAmir 150150 2020 11

ArielAriel 4040

TacTacomaoma

Total Total TacomaTacoma

255255 140140

BillBill 7070 8080 11

CoreyCorey 6565 6060 11

SueSue 120120

Could we do it differently ?

Yes …

Count(Filter (Descendants(Customers.CurrentMember.Customer.Name), (Sales>0) AND (Sales,Computers)>0) ))

But …

Not efficient as using the SUM function.

Page 27: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Analyzing the PropertiesAnalyzing the PropertiesExample for Member Properties:Gender is a property of a customer.Education Level Property of an employee.Store size is a property of a Store.

Amir Netz:

Demo, show where member properties are being defined, how they look in the dimension browser

Amir Netz:

Demo, show where member properties are being defined, how they look in the dimension browser

Page 28: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Analyzing the PropertiesAnalyzing the PropertiesExample for Member Properties:Gender is a property of a customer.Education Level Property of an employee.Store size is a property of a Store.

Misconception:Member properties are only used to provide additional informationon a dimension member.

The truth about member properties:Member properties are being constantly used in data analysis.

Two ways of using Member Properties in data analysis:1. Virtual Dimensions2. MDX

Amir Netz:

Virtual Dimensions demo

Amir Netz:

Virtual Dimensions demo

Page 29: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Business Problem:What is the sales average per SQFT ?

Analyzing the PropertiesAnalyzing the Properties

Remember: The Store Size (SQFT) is not a Measure.

SalesTotal SQFT in Location X

Sales/Sum(Descendants(Store.CurrentMember,Store.[Store Name]),Val(Store.CurrentMember.Properties(“SQFT”)))

Amir Netz:

Show demo and show another example for finding the perfect wife

Amir Netz:

Show demo and show another example for finding the perfect wife

Page 30: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Virtual CubeVirtual CubeLike a View in a relational database but yet different

Time

Customers Warehouse

Time

Products

Products

Page 31: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Virtual Cube and Virtual Cube and Calculated MembersCalculated Members

Customers Warehouse

Time

Products

Common Dimensions

Note: Cubes joined in a Virtual Cube, are not required to have the same number of Dimensions

Amir Netz:

Show virtual cube, different views, what is valid and what is not

Amir Netz:

Show virtual cube, different views, what is valid and what is not

Page 32: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Currency Conversion Currency Conversion

Business Problem:The sales database is holding sales transactions in US Dollars. The company needs to show the sales figures in number of currencies.

Solution:Two approaches:1. Present converted sales figures based on the

exchange rate at the time of the sales transaction.2. Sales figures will be converted to currency X based on today's

exchange rate.

Page 33: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Currency Conversion Currency Conversion Solution:Two approaches:1. Present converted sales figures based on the

exchange rate at the time of the sales transaction.2. Sales figures will be converted to currency X based on today's

exchange rate.

Steps:1. Create a “Currency” cube - Currency cube holds Currency exchange

rate history.2. Create Virtual Cube joining the “Currency” cube with the “Sales” cube.3. Create “Calculated Member” for currency conversion.

Page 34: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Ariel:

Following this slide will have a demo. Demo will show how to create the currency cube, and the virtual cube

Ariel:

Following this slide will have a demo. Demo will show how to create the currency cube, and the virtual cube

Currency Conversion Currency Conversion The “Currency” cube:

Dimensions:•Time•Currency

Measures:•Index - Currency exchange rate for US Dollar

Page 35: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Currency Conversion Currency Conversion The Calculated Member: SalesSales IndexIndex C. MemberC. Member

19981998

180180 66

Q1Q1 180180 66

JanJan 3030 1.51.5 4545

FebFeb 5050 22 100100

MarchMarch 100100 2.52.5 250250

????????X10801080

Page 36: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Currency Conversion Currency Conversion The Calculated Member: SalesSales IndexIndex C. MemberC. Member

19981998

180180 66

Q1Q1 180180 66

JanJan 3030 1.51.5 4545

FebFeb 5050 22 100100

MarchMarch 100100 2.52.5 250250

395395

Page 37: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Currency Conversion Currency Conversion The Calculated Member: SalesSales IndexIndex C. MemberC. Member

19981998

180180 66

Q1Q1 180180 66 395395

JanJan 3030 1.51.5 4545

FebFeb 5050 22 100100

MarchMarch 100100 2.52.5 250250

Sum (Descendents(Time.CurrentMember,Month), ValidMeasure([Unit Sales]) *ValidMeasure( Index))

Sum (each month sales in a given period * Index)Sum (Descendents(Time.CurrentMember,Month), [Unit Sales] * Index)

Amir Netz:

Demo.

Amir Netz:

Demo.

Page 38: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Currency Conversion Currency Conversion Solution:Two approaches:1. Present converted sales figures based on the

exchange rate at the time of the transaction.2. Sales figures will be converted to currency X based on today's

exchange rate.

Steps:• Create a “Currency” dimension in the “Sales” cube.• Create a calculated member for Currency conversion• Make it smarter by using a UDF.

Amir Netz:

Demo, show with fix value first then suggest to go to the web

Amir Netz:

Demo, show with fix value first then suggest to go to the web

Page 39: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

UDF - User Defined Function in MDXUDF - User Defined Function in MDX

UDF allows extension of the MDX UDF allows extension of the MDX languagelanguage

Any Automation library can be used Any Automation library can be used for UDF (VB, VC…)for UDF (VB, VC…) Just compile your VB class into an Just compile your VB class into an

ActiveX DLL and register the DLL in the ActiveX DLL and register the DLL in the OLAP ManagerOLAP Manager

Make sure to deploy the DLL on the Make sure to deploy the DLL on the client side!client side!

VBA and Excel are two libraries that VBA and Excel are two libraries that are automatically registered are automatically registered

Page 40: Solving Business Problems in OLAP Services Using MDX - Part II Amir Netz – Dev Manager & Architect Ariel Netz – Program Manager SQL Server OLAP Services

Creating a UDFCreating a UDF

Public Function Currency_Convert(Currency_Name As String) As Double Dim strHTML As String Dim URL As String Dim istart As Integer Dim iend As Integer Dim CurrencyRate As Double Select Case Currency_Name Case "German Mark" URL = "http://quote.yahoo.com/m5?a=1&s=USD&t=DEM" Case "British Pound" URL = "http://quote.yahoo.com/m5?a=1&s=USD&t=GBP" Case "Italian Lira" URL = "http://quote.yahoo.com/m5?a=1&s=USD&t=ITL" Case "French Franc" URL = "http://quote.yahoo.com/m5?a=1&s=USD&t=FRF" End Select strHTML = Form1.Inet1.OpenURL(URL) iend = InStr(1, strHTML, "</b></td></tr></table><", vbTextCompare) istart = InStr(1, strHTML, "</td><td><b>", vbTextCompare) CurrencyRate = Val(Replace(Mid(strHTML, istart + Len("</td><td><b>"), iend - istart - Len("</td><td><b>")), ",", "", 1)) Currency_Convert = CurrencyRate

End Function

Functionality: •Currency Covert ( Input: Currency Name to be converted)•Based on “Currency Name” go to exchange rate URL.•Download HTML•Parse HTML and extract exchange rate for “Currency Name”.•Return Exchange rate value.