using olap in mdx applications

Post on 31-Dec-2015

56 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

Using OLAP in MDX Applications. Kevin S. Goff. Kevin S. Goff: 30 seconds of Shameless Promotion. Developer/architect since 1987 Microsoft SQL Server MVP 2010 (C# MVP 2005-2009) Columnist for CoDe Magazine 2004-2008, 2010 Wrote a book, collaborated on a 2 nd book - PowerPoint PPT Presentation

TRANSCRIPT

Using OLAP in MDX Applications

Kevin S. Goff

04/19/2023 MDX in OLAP Applications 2

Kevin S. Goff: 30 seconds of Shameless Promotion• Developer/architect since 1987• Microsoft SQL Server MVP 2010 (C# MVP 2005-2009)• Columnist for CoDe Magazine 2004-2008, 2010• Wrote a book, collaborated on a 2nd book• Currently writing a 3rd book on Business Intelligence with SQL Server• Frequent speaker for .NET/Database/SharePoint User Group/community events• SQL Server/Business Intelligence Trainer/Courseware Author for SetFocus, LLC• kgoff@kevinsgoff.net • www.KevinSGoff.Net (Go to downloads area)

04/19/2023 MDX in OLAP Applications 3

The Agenda

1. SQL Server Reporting Services Examples:1. Showing a 52 week moving average where the parameter for year excludes the

first year 2. Implementing an MDX Rank across columns in a PIVOT Table3. Sales for a Day and for the previous day (going back as far as 7 days)4. Top N cities by Sales within Top Y Products by Sales

2. PerformancePoint Server1. Using MDX snippets in a KPI dashboard2. Using MDX in Analytic GRIDs and Analytic Charts for a % of Category Share

3. Excel1. Adding MDX Code to OLAP Pivot Tables using a free OLAP PivotTable Extension

add-on

4. Recommended Books/Links

04/19/2023 MDX in OLAP Applications 4

Showing a 52 week moving average in SSRS

04/19/2023 MDX in OLAP Applications 5

Showing a 52 week moving average in SSRS

1. Can use the OLAP query designer, but must add 2 calculated members to determine 12-month avg

04/19/2023 MDX in OLAP Applications 6

Showing a 52 week moving average in SSRS

2 different ways to calculate 12 month average, using MDX LASTPERIODS function. One uses an AVG (that ignores NULLs) and a second that uses a SUM and divides by 12

04/19/2023 MDX in OLAP Applications 7

An MDX Rank across columns in a PIVOT Table

04/19/2023 MDX in OLAP Applications 8

An MDX Rank across columns in a PIVOT Table

MDX code for the report uses the ORDER and FILTER to Rank against a named set.

Also uses EXISTS to rank each subcategory within a Country

04/19/2023 MDX in OLAP Applications 9

An MDX Rank across columns in a PIVOT Table

with set [OrderedCountriesSubCategories] as ORDER( filter( [Customer].[Country].Children * [Product].[SubCategory].Children, [Internet Sales Amount] <> null), [Internet Sales Amount], DESC) member [SalesRank] as RANK( ( [Customer].[Country].Currentmember, [Product].[SubCategory].CurrentMember), EXISTS( [OrderedCountriesSubCategories], [Customer].[Country].CurrentMember))

select { [Internet Sales Amount], [SalesRank] } on columns, [OrderedCountriesSubCategories] on rows from [Adventure Works]

04/19/2023 MDX in OLAP Applications 10

Sales for a Day and for the previous day (going back as far as 7 days)

This goes beyond just using PREVMEMBER to get sales for prior dayWill go back as far as 7 days

04/19/2023 MDX in OLAP Applications 11

Sales for a Day and for the previous day (going back as far as 7 days)

Uses MDX query parameters and references them in the MDX code

04/19/2023 MDX in OLAP Applications 12

Sales for a Day and for the previous day (going back as far as 7 days)

WITH MEMBER [SalesPriorBusinessDay] as ([Internet Sales Amount], tail( filter( { [Date].[Date].CurrentMember.Lag(7) : [Date].[Date].CurrentMember.PrevMember}, [Internet Sales Amount] > 0) ,1).Item(0)) , format_string = 'currency'

MEMBER [Measures].[LastSaleDate] AS tail( filter( { [Date].[Date].CurrentMember.Lag(7) : [Date].[Date].CurrentMember.PrevMember}, [Internet Sales Amount] > 0) ,1).Item(0).name

select { [Internet Sales Amount], [SalesPriorBusinessDay], [LastSaleDate]} on columns, order(filter( [Customer].[City].Children, [Internet Sales Amount] > 500), [Internet Sales Amount], desc) on rowsfrom [Adventure Works] where strtomember( @DateSelection)

04/19/2023 MDX in OLAP Applications 13

Top N cities by Sales within Top Y Products by Sales

Report allows us to get the top Y selling products, and for each product, give us the top N cities

Uses the MDX GENERATE function

04/19/2023 MDX in OLAP Applications 14

Top N cities by Sales within Top Y Products by Sales

04/19/2023 MDX in OLAP Applications 15

Top N cities by Sales within Top Y Products by Sales

with set [TopNProducts] as topcount( [Product].[Product].Children, @TopNProductCount, [Internet Sales Amount])

set [TopCitiesWithinTopProducts] as GENERATE ( [TopNProducts], ( [Product].[Product].CurrentMember, TOPCOUNT( [Customer].[City].Children, @TopNCityCount, [Internet Sales Amount] ) ) ) member [CityRank] as RANK( ( [Product].[Product].CurrentMember, [Customer].[City].CurrentMember), exists( [TopCitiesWithinTopProducts], [Product].[Product].CurrentMember)) member [Product Rank] as RANK( [Product].[Product].CurrentMember, [TopNProducts])

select { [Internet Sales Amount], [Product Rank], [CityRank]} on columns, [TopCitiesWithinTopPRoducts] on rowsfrom [Adventure Works] where strtoset( @FiscalYear)

04/19/2023 MDX in OLAP Applications 16

Using MDX snippets in a KPI dashboard

KPI Dashboard that receives a date as a parameter (could be year, could be quarter, etc.) and displays all the hierarchical children for that date selection

04/19/2023 MDX in OLAP Applications 17

Using MDX snippets in a KPI dashboard

In the Filter Link between the date dropdown and the KPI scorecard, we can build an MDX connection formula, to take the date selection and retrieve the hierarchical children

04/19/2023 MDX in OLAP Applications 18

Using MDX in Analytic GRIDs and Analytic Charts for a % of Category Share

Chart and report allow a user to select a product in the hierarchy. Chart shows monthly sales and also sales % of parent. Grid at bottom shows entire parent ancestry.

04/19/2023 MDX in OLAP Applications 19

Using MDX in Analytic GRIDs and Analytic Charts for a % of Category Share

Analytic grid takes product parameter, grabs siblings, and also grabs ascendants.Grid also uses Hierarchize to take all the UNIONED data and display in hierarchical orderWhen we write custom MDX code in PPS, we must declare parameters from filters manually

04/19/2023 MDX in OLAP Applications 20

Using MDX in Analytic GRIDs and Analytic Charts for a % of Category Share

SELECT [Dim Date Calendar].[Month Key].[Month Key].ALLMEMBERS ON COLUMNS,

hierarchize( union( ascendants( <<ProductParm>> ), <<ProductParm>>.Siblings ) ) ON ROWS

FROM [Jewel Destiny2008R2]

WHERE ( <<YearFilter>>, <<GeoFilter>>, [Measures].[Product Sales as % Parent] )

04/19/2023 MDX in OLAP Applications 21

Using MDX with Excel

1. Suppose, when browsing an OLAP cube using Excel, we want to incorporate an “on-the-fly” MDX calculation

2. We can use OLAP PivotTable Extensions (free utility) 3. After installing, we can right-click on a PivotTable column and add MDX formulas4. http://olappivottableextend.codeplex.com/ (32-bit)5. http://olappivottableextend.codeplex.com/releases/view/46306 (64-bit)

04/19/2023 MDX in OLAP Applications 22

Using MDX with Excel

([Measures].[Internet Sales Amount], PARALLELPERIOD( [Date].[Fiscal].[Fiscal Year], 1 ) ), format_string = '$#,###.##‘

Note: these formulas only reside in the spreadsheet – they are not written back to the OLAP database

04/19/2023 MDX in OLAP Applications 23

Recommended Books/Links

• Microsoft SQL Server 2008 MDX Step by Step– http://

www.amazon.com/Microsoft-SQL-Server-2008-Step/dp/0735626189/ref=sr_1_1?ie=UTF8&qid=1291449547&sr=8-1

• MDX Solutions: With Microsoft SQL Server Analysis Services 2005 – http://

www.amazon.com/MDX-Solutions-Microsoft-Analysis-Services/dp/0471748080/ref=sr_1_4?ie=UTF8&qid=1291449896&sr=8-4

• On my website (www.KevinSGoff.net), I’ve covered some MDX-related topics:– http://

kevin_s_goff.typepad.com/kevin_s_goff_weblog/2010/11/11-07-2010-setfocus-bisql-masters-program-tip-ssrs-2008ssrs-2008-r2-olap-reports-and-overwriting-mdx-parameters.html

– http://kevin_s_goff.typepad.com/kevin_s_goff_weblog/2010/01/1-17-2010---setfocus-bisql-masters-program-tip-when-prevmember-alone-isnt-enough-in-mdx.html

– http://kevin_s_goff.typepad.com/kevin_s_goff_weblog/2009/12/12-21-2009-reason-1-of-a-list-of-thousands-of-reasons-why-mdx-is-important.html

top related