Download presentation
Presentation is loading. Please wait.
Published byStuart West Modified over 6 years ago
1
Use the Power of Analytical Hierarchies in Your Cubes
Tim Peterson Mentor, SolidQ
2
Tim Peterson Independent mentor, working with SolidQ in the United States and Scandinavia Author of SolidQ’s two courses on MDX MDX for Business Logic Advanced MDX Author of two books on Microsoft Business Intelligence
3
Goals For This Presentation
Tell you about Analytical Hierarchies Show you how Analytical Hierarchies can be used Give you an introductory class on how to create Analytical Hierarchies using Calculation Hierarchies in a multidimensional cube
4
What Are Analytical Hierarchies?
A normal hierarchy subdivides data An Analytical Hierarchy allows you to analyze the data from different perspectives Analytical Hierarchies can be created with calculations in a multidimensional cube These Analytical Hierarchies are often called Calculation Hierarchies
5
Analytical Hierarchy Example
<Enter module number here> <Enter module name here> Analytical Hierarchy Example There are two ways that you could show the trend and the goal in an MDX cube: You could create a lot of calculated members, such as Internet Sales Trend, Internet Sales Goal, Reseller Sales Trend, and Reseller Sales Goal You could create an Analytical Hierarchy with three members—Actual, Trend, and Goal—and use the hierarchy for any measure you want We’re now going to have an extended example in creating a calculation hierarchy. We’re going to use this example as a way of introducing many of the capabilities of MDX scripting. First, we’re going to look at the end result – what a calculation hierarchy looks like in the end and compare it with creating separate calculated members. © 2012 SolidQ <Enter course name here>
6
<Enter module number here> <Enter module name here>
Separate Calculations Demo Here is the strategy for creating separate measures. NOTE: Separate Excel files have been created for this demo and the one on the next page. © 2012 SolidQ <Enter course name here>
7
<Enter module number here> <Enter module name here>
Analytical Hierarchy Demo Here are the same calculations in a calculation hierarchy. Show the following in this demo: How to use the calculation hierarchy in the filter, with measures on columns How selecting the Actual member of the hierarchy is the same as not using the hierarchy at all How to use the calculation hierarchy on the rows together with the date hierarchy How to set up the calculation hierarchy to use some measures but not other measures How to switch back to the spreadsheet with the separate calculations while discussing how limited your options are compared to what you can do with a calculation hierarchy © 2012 SolidQ <Enter course name here>
8
Using a Date Calculation Hierarchy
<Enter module number here> <Enter module name here> Using a Date Calculation Hierarchy One of the most popular types of Analytical Hierarchies is a Date Calculation Hierarchy Date Calculation Hierarchies are also referred to as Time Intelligence Hierarchies It’s useful to recognize that there are different types of date calculations. Each of these types has distinct characteristics. © 2012 SolidQ <Enter course name here>
9
Types of Date Calculations
<Enter module number here> <Enter module name here> Types of Date Calculations Current Date Periods Current Year, Current Month, Today Relative Date Periods Last Month, Same Month Last Year To Date Calculations, Rolling Averages YTD, Last Year YTD, 6 Month Rolling Avg Comparisons, Ratios, Projections Change From Last Month, % Change Last Month % Change YTD Last Year To This Year Full Year Forecast Based on YTD It’s useful to recognize that there are different types of date calculations. Each of these types has distinct characteristics. © 2012 SolidQ <Enter course name here>
10
Using Multiple Analytical Hierarchies
<Enter module number here> <Enter module name here> Using Multiple Analytical Hierarchies Many applications use multiple dates Order Date Due Date Ship Date The calculations are needed for all dates A separate hierarchy is built to allow the user to select the desired date It is often useful to apply the date calculations to more than a single date. Adventure Works has three dates. Some cubes have 10 or 20 different date dimensions, all of which are used for analysis. By using a second hierarchy, you can use one set of time calculations for multiple data hierarchies. © 2012 SolidQ <Enter course name here>
11
Behavior of Current Date Periods
<Enter module number here> <Enter module name here> Behavior of Current Date Periods With current date periods, you can create views of the data that can be reused without modification A view showing the current month will always show the current month, without the user needing to change the month when they open the view Some organizations may want one of the current date periods to be the default Current Year or Current Month might be selected By using current date periods, you can create an Excel spreadsheet that is displaying the current month’s data. Whenever it is opened, it will always show the current month. © 2012 SolidQ <Enter course name here>
12
Current Periods With Date Hierarchy
<Enter module number here> <Enter module name here> Current Periods With Date Hierarchy When used together with the date hierarchy, the Current Month member Displays values for only the current month and the days within the current month Returns null for other months Displays the value of the current month at higher levels Displays the value of the current month at the All level The relative date calculations have noticeably different behavior when they are used together with the date hierarchy and apart from the date hierarchy. Here is how they work together with the date hierarchy. © 2012 SolidQ <Enter course name here>
13
<Enter module number here> <Enter module name here>
Current With Date Hierarchy Point out what was discussed on the previous slide. © 2012 SolidQ <Enter course name here>
14
Current Periods Without Date Hierarchy
<Enter module number here> <Enter module name here> Current Periods Without Date Hierarchy When used without the date hierarchy: The Current Month member slices the data on the current month The Current 4 Months member slices the data on the current and past 3 months The Current Year member slices the member on the current year Current period date calculations would normally be used in this way, without the date hierarchy There’s different behavior when not using a date hierarchy. © 2012 SolidQ <Enter course name here>
15
<Enter module number here> <Enter module name here>
Current Without Date Hierarchy Here are the relative period calculations without a date hierarchy. All the information about products is displayed for the current month. © 2012 SolidQ <Enter course name here>
16
Relative Periods With Date Hierarchy
<Enter module number here> <Enter module name here> Relative Periods With Date Hierarchy When used together with the date hierarchy, the Previous Month member: Displays the aggregated value for the entire previous month on the day level Displays the value for the previous month on the month level Displays “NA” on higher levels Displays value for the previous month at the All level Here is how the relative date period calculations work together with the date hierarchy. © 2012 SolidQ <Enter course name here>
17
<Enter module number here> <Enter module name here>
Relative With Date Hierarchy As explained on the previous slide, point out: The aggregated value for the entire previous month on the day level The value for the previous month on the month level The value of “NA” on higher levels The value for the previous month at the All level © 2012 SolidQ <Enter course name here>
18
Relative Periods Without Date Hierarchy
<Enter module number here> <Enter module name here> Relative Periods Without Date Hierarchy When used without the date hierarchy: The Previous Month member slices the data to show only the previous month The Same Month Last Year member slices the data to show only the same month from last year Relative period date calculations are most often used without the date hierarchy As with the current period date calculations, the relative date period calculations are most commonly used without the date hierarchy. © 2012 SolidQ <Enter course name here>
19
<Enter module number here> <Enter module name here>
Relative Without Date Hierarchy Here is an example of a relative period calculation used without a date hierarchy. The Previous Month member is displayed. © 2012 SolidQ <Enter course name here>
20
To-Date and Rolling Average
<Enter module number here> <Enter module name here> To-Date and Rolling Average When used with the date hierarchy, to-date and rolling average calculations are evaluated for every appropriate date member If you are looking at a Rolling 6 Month Average, you can see how the value changes from month to month At the All level it would show the Rolling Average based on the current date The calculation would be set to null for all other levels Now we look at the third category of time calculations – those calculating to-date values and rolling averages. © 2012 SolidQ <Enter course name here>
21
To-Date and Rolling Average (Continued)
<Enter module number here> <Enter module name here> To-Date and Rolling Average (Continued) When used without the date hierarchy, to-date and rolling average calculations are evaluated from the perspective of the current date For a Rolling 6-Month Average, that would be from the perspective of the current month In some cubes, these calculations are set to null if the date hierarchy is not used Without the date hierarchy, the to-date and rolling average calculations are evaluated from the perspective of the current date. © 2012 SolidQ <Enter course name here>
22
<Enter module number here> <Enter module name here>
YTD With Date Hierarchy This is an example of a to-date calculation used with the date hierarchy. © 2012 SolidQ <Enter course name here>
23
Comparisons, Ratios, and Projections
<Enter module number here> <Enter module name here> Comparisons, Ratios, and Projections This final category of date calculations are the members that are truly calculations Comparisons give the difference between periods Ratios show percentage changes and growth Projections take other values and extrapolate future results When used with a date hierarchy, values are given for each appropriate member When used without a date hierarchy, values are given from the perspective of the current date Comparisons, ratios, and projections have behavior similar to the to-date calculations. © 2012 SolidQ <Enter course name here>
24
<Enter module number here> <Enter module name here>
Ratio With Date Hierarchy Here is a ratio calculation used with the date hierarchy. © 2012 SolidQ <Enter course name here>
25
<Enter module number here> <Enter module name here>
Ratio Without Date Hierarchy Here is a ratio calculation used without the date hierarchy. © 2012 SolidQ <Enter course name here>
26
Creating Calculation Hierarchies
<Enter module number here> <Enter module name here> Creating Calculation Hierarchies Know how to use MDX to create calculations Learn how to write MDX script code Learn the basic principles for creating calculations in a Calculation Hierarchy Learn to imagine how you can use Calculation Hierarchies in your organization One of the most useful ways to use the MDX Script is to create a calculation hierarchy. The time calculation hierarchy that we’re going to cover in the next module is a specialized form of this hierarchy. In this module, we’re going to show how to create a basic calculation hierarchy. © 2012 SolidQ <Enter course name here>
27
Calculation Hierarchy Basics
<Enter module number here> <Enter module name here> Calculation Hierarchy Basics A Calculation Hierarchy is created in the MDX Script The default member shows the data the way it would be as if the Calculation Hierarchy did not exist All the other members are calculations One of the most useful ways to use the MDX Script is to create a calculation hierarchy. The time calculation hierarchy that we’re going to cover in the next module is a specialized form of this hierarchy. In this module, we’re going to show how to create a basic calculation hierarchy. © 2012 SolidQ <Enter course name here>
28
<Enter module number here> <Enter module name here>
The Source Table Here is a named query used as the source table for the Calculation Hierarchy: SELECT 'Actual' AS AttName, 10 AS AttKey UNION SELECT '3 Year Trend' AS AttName, 20 AS AttKey SELECT 'Incentive Goal' AS AttName, 30 AS AttKey Here’s how to use a named query in the data source view to create real members for the calculation hierarchy. NOTE: This named query will not be in the cube until you create it. You have a choice when running this demo: Create this named query and the dimension ahead of time, and show it to the students in this demo. Create the named query as you are teaching and then use it to create the dimension and add the dimension to the cube. I prefer this second strategy. However, if you use it, make sure you practice it, so you don’t spend a long time doing it – and maybe not get things named right. ALSO NOTE: The demo code has many copies of the script code as it is developed in these slides. I recommend pasting the whole demo into the MDX Script, commenting it all out, and then uncommenting each portion as you cover it in the demos. © 2012 SolidQ <Enter course name here>
29
<Enter module number here> <Enter module name here>
Results: Starting Hierarchy This is how the hierarchy looks right after you have created it, before doing any assignments in the MDX Script. Note how all three of the members returned the same data. So far the new hierarchy is not affecting the data at all. © 2012 SolidQ <Enter course name here>
30
<Enter module number here> <Enter module name here>
Scopes The portion of the cube for an assignment is called a subcube or scope A subcube is defined by specifying one or more sets Subcube punctuation includes: Parentheses around the entire subcube Commas separating each of the sets Subcube punctuation is identical to the punctuation of the MDX Where clause Values are assigned in the MDX Script for a particular portion of the cube. This portion is called the subcube or scope. EMPHASIZE: The terms subcube and scope are used interchangeably. These two words mean exactly the same thing. © 2012 SolidQ <Enter course name here>
31
Scopes in the MDX Script
<Enter module number here> <Enter module name here> Scopes in the MDX Script You can make assignments with a subcube in an MDX Script two ways: Directly, using the subcube definition with an equal sign (=) Using a Scope block Scopes allow you to nest assignments Codes written with scopes can be easier to read There are two ways to write subcubes in the MDX Script. NOTE: My personal preference is to use Option 2 only. The code in this course uses Option 2, but it is common to mix the two options. For example, the Business Intelligence Wizard uses both options together when creating a time calculation hierarchy. © 2012 SolidQ <Enter course name here>
32
Demo: Subcube Code Option #1
<Enter module number here> <Enter module name here> Demo: Subcube Code Option #1 //OPTION 1 ( {[Sales Trend And Incentive Goal].[Actual Trend Or Goal].&[20] ,[Sales Trend And Incentive Goal].[Actual Trend Or Goal].&[30] } ) = null; This code demonstrates the two options. The results are identical. Option 1 is a direct assignment. Option 2 sets up the subcube with the Scope statement and then makes the assignment with the syntax “this = null;” It’s important to understand the meaning of “this” in the cube. “This” refers to whatever subcube (or scope) of the cube is currently in effect. In this example, the two calculations are being initialized to null values. Leave one of these two options uncommented in the cube. It is needed for the initial assignments in the calculation hierarchy. © 2012 SolidQ <Enter course name here>
33
Demo: Subcube Code Option #2
<Enter module number here> <Enter module name here> Demo: Subcube Code Option #2 //OPTION 2 scope ( {[Sales Trend And Incentive Goal].[Actual Trend Or Goal].&[20] ,[Sales Trend And Incentive Goal].[Actual Trend Or Goal].&[30] } ); this = null; end scope; This code demonstrates the two options. The results are identical. Option 1 is a direct assignment. Option 2 sets up the subcube with the Scope statement and then makes the assignment with the syntax “this = null;” It’s important to understand the meaning of “this” in the cube. “This” refers to whatever subcube (or scope) of the cube is currently in effect. In this example, the two calculations are being initialized to null values. Leave one of these two options uncommented in the cube. It is needed for the initial assignments in the calculation hierarchy. © 2012 SolidQ <Enter course name here>
34
<Enter module number here> <Enter module name here>
Results: After Initializing Here is what the hierarchy looks like after the members are initialized. The Actual member is still displaying the unchanged data. The other two members are displaying the null value that was assigned in the initialization. © 2012 SolidQ <Enter course name here>
35
<Enter module number here> <Enter module name here>
More on Assignments MDX Script code can get very complex Keep it simple: Start with a code template Use embedded scope statements to keep your code organized Handle boundary situations only after you know the main code is working Here are some general guidelines to keep in mind when you are creating assignments. © 2012 SolidQ <Enter course name here>
36
Demo: MDX Script Template – Part 1
<Enter module number here> <Enter module name here> Demo: MDX Script Template – Part 1 scope ( { [Measures].[Internet Sales Amount] ,[Measures].[Internet Tax Amount] ,[Measures].[Reseller Sales Amount] ,[Measures].[Reseller Tax Amount] } ); Start with a template and make sure it works before writing the actual calculations. © 2012 SolidQ <Enter course name here>
37
Demo: MDX Script Template – Part 2
<Enter module number here> <Enter module name here> Demo: MDX Script Template – Part 2 scope ( [Sales Trend And Incentive Goal].[Actual Trend Or Goal].&[20] ); this = 20; end scope; scope( [Sales Trend And Incentive Goal].[Actual Trend Or Goal].&[30] this = 30; Start with a template and make sure it works before writing the actual calculations. © 2012 SolidQ <Enter course name here>
38
<Enter module number here> <Enter module name here>
Results: MDX Script Template Here are the results of the script template. Note that the values that were set in the template are displayed at every level. © 2012 SolidQ <Enter course name here>
39
<Enter module number here> <Enter module name here>
Assignments by Level Assignments are often made by level When you make assignments on one level, all higher levels are automatically modified, with new aggregated values that include the values that you have assigned The template doesn’t show a realistic result. Normally assignments are applied to a specific level. © 2012 SolidQ <Enter course name here>
40
Demo: Assigning One Level
<Enter module number here> <Enter module name here> Demo: Assigning One Level scope ( [Sales Trend And Incentive Goal].[Actual Trend Or Goal].&[20] ); [Date].[Fiscal].[Fiscal Quarter].members this = 20; end scope; Here the template is modified to make the assignment only on the Fiscal Quarter level. © 2012 SolidQ <Enter course name here>
41
<Enter module number here> <Enter module name here>
Results: Assigning One Level When assigning one level, note that: There are nulls at the lower levels. There are the actual assigned values at the level the assignments were made. There are aggregations at the higher levels. © 2012 SolidQ <Enter course name here>
42
Including the Default Member
<Enter module number here> <Enter module name here> Including the Default Member When you are creating the calculations for a Calculation Hierarchy, you must include a direct or indirect reference to the default member If you don’t do this, you will either see null values or an infinite recursion error You have to start with the existing data! The current member of the Calculation Hierarchy is the calculated member being assigned, which is null before the assignment Now we’re going to create the calculation itself. Normally we refer to the default member of the calculation hierarchy. If we don’t, we’ll either get null values or an infinite recursion error The reference can be direct, where the default member is actually referenced. It can also be indirect, where another calculation is referenced that in turn references the default member. © 2012 SolidQ <Enter course name here>
43
Demo: Default Member Missing
<Enter module number here> <Enter module name here> Demo: Default Member Missing scope ( [Date].[Fiscal].[Fiscal Quarter].members ); this = avg( { [Date].[Fiscal].CurrentMember.lag(12): [Date].[Fiscal].CurrentMember.lag(1) } ,Measures.CurrentMember end scope; Here is the code that results in a null value or infinite recursion. © 2012 SolidQ <Enter course name here>
44
<Enter module number here> <Enter module name here>
Results: Default Member Missing! You will get either null values or an infinite recursion error. Here the infinite recursion error that can be displayed. The query in the demo file is displaying null values. Null values or the infinite recursion error can occur in very similar situations. It’s important to emphasize to the students that, no matter which error occurs, the reason is that no member with data has been included in the calculation. © 2012 SolidQ <Enter course name here>
45
Demo: Default Member Added
<Enter module number here> <Enter module name here> Demo: Default Member Added scope([Date].[Fiscal].[Fiscal Quarter].members); this = avg ( { [Date].[Fiscal].CurrentMember.lag(12): [Date].[Fiscal].CurrentMember.lag(1) * [Sales Trend And Incentive Goal].[Actual Trend Or Goal].&[10] } ,Measures.CurrentMember ); end scope; Here the problem is fixed by adding a reference to the default member of the hierarchy. This default member, Actual, has a value that can be used for starting the calculation. © 2012 SolidQ <Enter course name here>
46
<Enter module number here> <Enter module name here>
Results: Default Member Added Here are the results when the error is fixed. © 2012 SolidQ <Enter course name here>
47
<Enter module number here> <Enter module name here>
Using the BI Wizard The BI Time Intelligence Wizard provides an automated way to create a Time Calculation Hierarchy You choose the following: Which date hierarchy will be used for the calculations Measures you want the calculations to be applied to The calculations you want to have applied Here’s a description of how the wizard creates a time calculation hierarchy. © 2012 SolidQ <Enter course name here>
48
Using the BI Wizard (Continued)
<Enter module number here> <Enter module name here> Using the BI Wizard (Continued) The wizard does the following: Adds the hierarchy to the selected date dimension Adds a calculated field in the data source view to be used as the default value for the hierarchy Creates each of the other members of the hierarchy as calculated members Adds a scope statement containing all the selected measures Adds separate blocks of code assigning values to each of the selected calculations Here is what the wizard does automatically when it creates the time calculation hierarchy. © 2012 SolidQ <Enter course name here>
49
Customizing Time Intelligence
<Enter module number here> <Enter module name here> Customizing Time Intelligence Users can customize and/or extend the code created by the BI Wizard It can also be useful to create a Time Calculation Hierarchy without using the wizard The wizard uses calculated members for the hierarchy You can use real members for the calculations Some users start with the time calculation hierarchy created by the wizard and then extend or customize it. There are advantages in not using the wizard, including the option of using real members for the calculations. © 2012 SolidQ <Enter course name here>
50
Steps to Create a Customized Hierarchy
<Enter module number here> <Enter module name here> Steps to Create a Customized Hierarchy Write a named query in the data source view to create the members that you want to have in your hierarchy Include both a field for a key and a field for a name Create the dimension for the hierarchy Set the default member of the hierarchy Set the IsAggregatable property of the hierarchy’s one attribute to False The steps for creating a customized hierarchy are the same steps we used in the last module to create the calculation hierarchy. Remember that a time calculation hierarchy is a specialized type of calculation hierarchy. © 2012 SolidQ <Enter course name here>
51
Creating a Hierarchy (Continued)
<Enter module number here> <Enter module name here> Creating a Hierarchy (Continued) Add the dimension to the cube Create a Scope block in the MDX Script, including all the measures for which you want to assign the calculations Create embedded separate Scope blocks for each of the members of the hierarchy As necessary, create separate embedded Scope blocks to handle specific levels Assign formatting as necessary Here are the rest of the steps. © 2012 SolidQ <Enter course name here>
52
Determining the Current Date
<Enter module number here> <Enter module name here> Determining the Current Date Many date calculations reference the current date There are three common strategies that are used to reference today’s date: Use VBAMDX!Now() with string functions and StrToMember to relate the current date with the correct member of the date hierarchy Add a new day to the date hierarchy every day, so that the last member of the date hierarchy is either today or some fixed number of days from today Have an attribute in the date dimension identifying today’s date, which is updated every day If the calculations are used apart from the date hierarchy, it’s necessary for the calculations to reference the current date. This slide describes three ways of doing that. The first strategy may not perform as well as the others because it will prevent the use block computation. © 2012 SolidQ <Enter course name here>
53
Demo: Current Date Strategy 1
<Enter module number here> <Enter module name here> Demo: Current Date Strategy 1 with set CurrentDate as strtoset ( "{[Date].[Calendar].[Date].&[" + vbamdx!format vbamdx!dateadd("YYYY",-6,now()) ,"yyyyMMdd" ) + "]}" select CurrentDate on 0from [AW4] Here is the code for the relative date period using the first strategy to find the current date. Because the Adventure Works 2012 database does not include current data, the calculation is adjusted to find the current date from 6 years ago. © 2012 SolidQ <Enter course name here>
54
Demo: Current Date Strategy 2
<Enter module number here> <Enter module name here> Demo: Current Date Strategy 2 with set CurrentDate as closingperiod ( [Date].[Calendar].[Date] ,[Date].[Calendar].[All Periods] ) select CurrentDate on 0 from [Adventure Works] Here is the code for the second strategy. Note that this code will work only if the current date is the last member of the Calendar hierarchy of the Date dimension. It requires that the dimension be updated every day. © 2012 SolidQ <Enter course name here>
55
Demo: Current Date Strategy 3
<Enter module number here> <Enter module name here> Demo: Current Date Strategy 3 with set CurrentDate as exists ( [Date].[Calendar].[Date].members ,[Date].[Is Today].[Today] ) select CurrentDate on 0 from [Adventure Works] Here is the code for the third strategy. This strategy also requires that the Date dimension be processed every day. © 2012 SolidQ <Enter course name here>
56
Demo: Implementing Strategy 3
<Enter module number here> <Enter module name here> Demo: Implementing Strategy 3 Calculated field in DSV for “Today” attribute case when convert (date, dateadd(yyyy, -6, getdate())) = convert(date, FullDateAlternateKey) then 'Today' else 'Not Today' end This is the code used in the data source view for the Adventure Works sample in this course. There is a 6-year time lag so the actual dates in Adventure Works will be found. Every time the Date dimension is processed by means of a full process or incremental update, the new date will be entered. © 2012 SolidQ <Enter course name here>
57
Demo: Code for Current Date Period
<Enter module number here> <Enter module name here> Demo: Code for Current Date Period scope([Select Date Period].[Date Period].[Current Month]); this = null; scope ( descendants exists [Date].[Calendar].[Month].members ,[Date].[Is Today].[Today] ).item(0) ) ); this = ([Select Date Period].[Date Period].[None Selected]); end scope; Here is sample code that assigns a current date period calculation. © 2012 SolidQ <Enter course name here>
58
Demo: Code for To-Date Calculation
<Enter module number here> <Enter module name here> Demo: Code for To-Date Calculation scope([Select Date Period].[Date Period].[Year To Date]); scope([Date].[Calendar].members); this = aggregate ( [Select Date Period].[Date Period].[None Selected] * ytd([Date].[Calendar].CurrentMember) ); end scope; Here is sample code that assigns a to-date calculation. The first scope applies the calculation to all levels, except the All level. © 2012 SolidQ <Enter course name here>
59
Demo: Code for To-Date Calculation
<Enter module number here> <Enter module name here> Demo: Code for To-Date Calculation scope([Date].[Calendar].[All Periods]); this = aggregate ( ytd exists [Date].[Calendar].[Date].members ,[Date].[Is Today].[Today] ).item(0) ) * [Select Date Period].[Date Period].[None Selected] ); end scope; Here is the assignment for the All level, showing year-to-date values for the current year. © 2012 SolidQ <Enter course name here>
60
Demo: Code for Relative Period Part 1
<Enter module number here> <Enter module name here> Demo: Code for Relative Period Part 1 scope([Select Date Period].[Date Period].[Previous Month]); this = null; scope([Date].[Calendar].[Date].members); this = ( [Select Date Period].[Date Period].[None Selected] ,[Date].[Calendar].CurrentMember.parent.lag(1) ); end scope; scope([Date].[Calendar].[Month].members); ,[Date].[Calendar].CurrentMember.lag(1) Here is sample code that assigns a relative period calculation. © 2012 SolidQ <Enter course name here>
61
Demo: Code for Relative Period Part 2
<Enter module number here> <Enter module name here> Demo: Code for Relative Period Part 2 scope([Date].[Calendar].[Calendar Quarter].members); this=iif ( aggregate([Date].[Calendar].CurrentMember.children) > 0 ,"NA" ,Null ); end scope; scope([Date].[Calendar].[Calendar Semester].members); this = max([Date].[Calendar].CurrentMember.children); scope([Date].[Calendar].[Calendar Year].members); Here is the rest of the sample code. The “NA” value has to be assigned separately to each level. The IIF function is used to prevent “NA” from being assigned when all the descendants of a member are null. In those cases, we also want the higher levels to be null, so they can be eliminated by Non Empty. © 2012 SolidQ <Enter course name here>
62
Demo: Code for Relative Period Part 3
<Enter module number here> <Enter module name here> Demo: Code for Relative Period Part 3 scope([Date].[Calendar].[All Periods]); this = ( exists [Date].[Calendar].[Month].members ,[Date].[Is Today].[Today] ).item(0).lag(1) ,[Select Date Period].[Date Period].[None Selected] ); end scope; Here is the rest of the sample code. The “NA” value has to be assigned separately to each level. The IIF function is used to prevent “NA” from being assigned when all the descendants of a member are null. In those cases, we also want the higher levels to be null, so they can be eliminated by Non Empty. © 2012 SolidQ <Enter course name here>
63
<Enter module number here> <Enter module name here>
Demo: Code for Ratio scope([Select Date Period].[Date Period].[% YTD Change Last Year]); scope([Date].[Calendar].members); this = iif ( [Select Date Period].[Date Period].[YTD Last Year] = 0 ,null , ( [Select Date Period].[Date Period].[Year To Date] - [Select Date Period].[Date Period].[YTD Last Year] ) / ); end scope; Here is the calculation for a ratio. © 2012 SolidQ <Enter course name here>
64
Code for Two Hierarchies
<Enter module number here> <Enter module name here> Code for Two Hierarchies The following are needed to implement the two hierarchies: Create a second named query in the data source view, a second new dimension, and connect that dimension to the cube Modify the code to add a separate block for each of the types of dates Most of this code can be created by cutting and pasting, using search and replace to change the name of the date There is a lot of copying and pasting code when adding the second hierarchy. All of the code has to be repeated because a scope cannot be reused with different members. © 2012 SolidQ <Enter course name here>
65
<Enter module number here> <Enter module name here>
Assigning Formatting Assign formatting in the Scope blocks as appropriate for specific time calculation members Such as the format Percent for ratios After all the calculations have been made, formatting may have to be reapplied Do this last, because some calculations cause formatting to be removed Group the measures into categories, based on their type of formatting Formatting is done after all the assignments are made. © 2012 SolidQ <Enter course name here>
66
Demo: Assigning Formatting 1
<Enter module number here> <Enter module name here> Demo: Assigning Formatting 1 scope ( MeasureGroupMeasures("Internet Sales") + MeasureGroupMeasures("Reseller Sales") + MeasureGroupMeasures("Sales Summary") - [Measures].[Internet Extended Amount] - [Measures].[Internet Order Quantity] - [Measures].[Reseller Order Quantity] - [Measures].[Order Quantity] ); Format_String(this) = "Currency"; Here is the first half of the assignments for the format string. This block assigns all the formatting for the monetary measures. © 2012 SolidQ <Enter course name here>
67
Demo: Assigning Formatting 2
<Enter module number here> <Enter module name here> Demo: Assigning Formatting 2 scope ( { [Select Date Period].[Date Period].&[80] --% Change Previous Month ,[Select Date Period].[Date Period].&[90] --% YTD Change Last Year } ); Format_String(this) = "Percent"; end scope; Here is the first half of the assignments for the format string. This block assigns all the formatting for the monetary measures. © 2012 SolidQ <Enter course name here>
68
Demo: Assigning Formatting 3
<Enter module number here> <Enter module name here> Demo: Assigning Formatting 3 scope ( { [Measures].[Internet Order Quantity] ,[Measures].[Reseller Order Quantity] ,[Measures].[Order Quantity] } ); Format_String(this) = "#,###"; This code block assigns the formatting for the non-monetary measures. © 2012 SolidQ <Enter course name here>
69
Demo: Assigning Formatting 4
<Enter module number here> <Enter module name here> Demo: Assigning Formatting 4 scope ( { [Select Date Period].[Date Period].&[80] --% Change Previous Month ,[Select Date Period].[Date Period].&[90] --% YTD Change Last Year } ); Format_String(this) = "Percent"; end scope; This code block assigns the formatting for the non-monetary measures. © 2012 SolidQ <Enter course name here>
70
Once More – The Goals For This Presentation
Tell you about Analytical Hierarchies Show you how Analytical Hierarchies can be used Give you an introductory class on how to create Analytical Hierarchies using Calculation Hierarchies in a multidimensional cube
71
Thank you very much!
72
Explore Everything PASS Has to Offer
Free SQL Server and BI Web Events Free 1-day Training Events Regional Event This is Community Business Analytics Training Local User Groups Around the World Session Recordings PASS Newsletter Free Online Technical Training
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.