+ All Categories
Home > Documents > Using OLAP in MDX Applications

Using OLAP in MDX Applications

Date post: 31-Dec-2015
Category:
Upload: charles-houston
View: 50 times
Download: 4 times
Share this document with a friend
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
23
Using OLAP in MDX Applications Kevin S. Goff
Transcript
Page 1: Using OLAP in MDX Applications

Using OLAP in MDX Applications

Kevin S. Goff

Page 2: Using OLAP in MDX Applications

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• [email protected] • www.KevinSGoff.Net (Go to downloads area)

Page 3: Using OLAP in MDX Applications

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

Page 4: Using OLAP in MDX Applications

04/19/2023 MDX in OLAP Applications 4

Showing a 52 week moving average in SSRS

Page 5: Using OLAP in MDX Applications

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

Page 6: Using OLAP in MDX Applications

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

Page 7: Using OLAP in MDX Applications

04/19/2023 MDX in OLAP Applications 7

An MDX Rank across columns in a PIVOT Table

Page 8: Using OLAP in MDX Applications

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

Page 9: Using OLAP in MDX Applications

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]

Page 10: Using OLAP in MDX Applications

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

Page 11: Using OLAP in MDX Applications

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

Page 12: Using OLAP in MDX Applications

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)

Page 13: Using OLAP in MDX Applications

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

Page 14: Using OLAP in MDX Applications

04/19/2023 MDX in OLAP Applications 14

Top N cities by Sales within Top Y Products by Sales

Page 15: Using OLAP in MDX Applications

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)

Page 16: Using OLAP in MDX Applications

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

Page 17: Using OLAP in MDX Applications

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

Page 18: Using OLAP in MDX Applications

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.

Page 19: Using OLAP in MDX Applications

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

Page 20: Using OLAP in MDX Applications

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] )

Page 21: Using OLAP in MDX Applications

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)

Page 22: Using OLAP in MDX Applications

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

Page 23: Using OLAP in MDX Applications

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


Recommended