You are on page 1of 31

Creating First Cube in SSAS 2008

Nowadays, analytical solutions are becoming mission critical for many organizations. Microsoft SQL Server 2008 Analysis Services (SSAS) is designed to provide exceptional performance and scalable support with millions of records and thousands of users from different locations. Why to Build a Cube? There are many advantages of cube over relational data mart. While querying a data mart, you can get most of the results but not everything you need for business analysis and decision making. Cube can help you to get answers of all "What-If" scenarios. Building a cube helps to house your data to centralize the business rules for calculations that you can't easily store in a relational data mart. The structure of the cube makes it much easier to write queries to compare data year over year (YOY), or to create cumulative values such as year-to-date (YTD) sales. Scalable Infrastructure - Analysis Services can scale to support databases of many terabytes in size with many thousands of users. Superior Performance - Analysis Services cubes are multidimensional structures that enable fast access to high volumes of pre-aggregated data, empowering end users to gain insight into relevant business data at the speed of thought. You gain the ability to manage aggregated data in the cube. To improve query performance in a relational data mart, we often create summary tables to prepare data for queries that don't require transaction-level detail. SSAS creates the logical equivalent of summary tables (called aggregations) and keeps them up-to-date.

I would like to introduce beginners to Microsoft SQL Server Analysis Services (SSAS) by creating a simple cube from AdventureWorksDW2008R2. You can install this database from codeplex. I'll cover following things in this article: 1. 2. 3. 4. 5. 6. Creating Analysis Services Project Creating Data Source Creating Data Source View Creating Cube and Dimensions Creating Dimension Hierarchies Deploying Cube Database from BIDS

Creating Analysis Services Project. First step is to create a project in Business Intelligence Development Studio (BIDS). Launch BIDS from Start --> All Programs --> Microsoft SQL Server 2008 --> SQL Server Business Intelligence Development Studio and then click File --> New --> Project. In the New Project dialog box, select Analysis Services Project. In the Name text box, type Learns AS and, if you like, change the location for your project. I'll store this project at location D:\Hari. Click OK to create the project.

Creating Data Source Now add a data source to define the connection string for data mart AdventureWorksDW2008R2. In Solution Explorer, right-click the Data Sources folder and click New Data Source.

In the Data Source Wizard, click Next on the Welcome to the Data Source Wizard page if it hasn't been disabled. On the Select how to define the connection page, click New to set up a new connection. In the Connection Manager, the default provider is the Native OLE DB\SQL Server Native Client 10.0, which is correct for our project. To define the connection, type the name of your server in the Server Name text box. Alternatively you can select it from the drop-down list, then select AdventureWorksDW2008R2 in the database drop-down list and click Test Connection button to check the connection. Finally click on OK as shown below:

When you're back in the Data Source Wizard, click Next. On the Impersonation Information page, select Use the service account option so that service account will be used to read data from the source when loading data into your SSAS database and service account must have read permissions to do so. Click Next and then Finish to complete the wizard. Creating Data Source View Now next step is to create a data source view (DSV) from the data source to define dimensions and cubes. You can make changes to the DSV without modifying the actual data source, which is very useful if you have only read permissions to the data mart. In Solution Explorer, right-click on the Data Source Views folder and then click New Data Source Views...You can see Data Source View Wizard. Click Next on the Welcome page. On the Select a Data Source page, select the data source just added to the project (Adventure Works DW2008R2.ds) and click Next. Now add required objects to the DSV by double-clicking each table or view on Select Tables and Views page. I want to add the following tables to the DSV to make it easy to understand for beginners: DimDate, DimProduct, DimProductCategory, DimProductSubcategory, and FactInternetSales. You can always add more tables later if you want to explore advance BI questions. Now click Next in the Data Source View Wizard once you are finished adding required tables followed by click on Finish. You can give a name to your DSV before clicking Finish button. I would recommend you to change the name of objects by selecting each one in the DSV designer and remove the Dim and Fact prefixes from the FriendlyName property because when you create dimensions and cubes, only FriendlyName property will be assigned to the objects. The DSV is shown below:

Creating Cube and Dimensions Next step is to create a Cube and Dimensions from the data source view. In Solution Explorer, right-click on the Cubes folder and then click New Cube...You can see Cube Wizard. Click on Next in Welcome to the Cube Wizard page.On the Select Creation Method page, keep the default option Use existing tables

and click Next button. On the Select Measure Group Tables page, choose InternetSales table and click Next.

Now the wizard displays all the measures available in the selected measure group tables. Measures are basically numeric values e.g. OrderQuantity, Unit Price, Sales Amount, Tax Amount etc. Select only the following measures from Internet Sales Group: Order Quantity, Unit Price, Total Product Cost, Sales Amount, and Internet Sales Count

Now click on Next button to open Select New Dimensions page and select Date and Product dimensions. Click Next to proceed.

In the Completing the Wizard page, enter the cube name as AdventureWorksCube and click Finish button to complete the wizard. Cube layout is shown below:

Now click on each dimensions and add required attributes from the Data Source View. Date Dimension: Drag and drop FullDateAlternateKey, Calendar Year, CalendarQuarter, EnglishMonthName, and EnglishDayNameOfWeek. Rename FullDateAlternateKey with Full Date, EnglishMonthName with Calendar Month, and EnglishDayNameOfWeek with Calendar Week as shown below:

Product Dimension: Drag and drop EnglishProductCategoryName from ProductCategory table, EnglishProductSubcategoryName from ProductSubcategory table and Color, ModelName, Size and Weight from Product table. Creating Dimension Hierarchies Navigate to Date Dimension Structure. Drag and drop Calendar Year attribute into Hierarchies surface area following by Calendar Quarter, Calendar Month, Calendar Week , and Full Date attributes. Rename hierarchy with Calendar. You'll see a warning mark in the hierarchy because attribute relationship is not set properly.

Set Attribute Relationships Click on the Attribute Relationships tab in the dimension designer. This tab is available only in Analysis Services 2008. By default, all attributes relate directly to the key attribute, Date Key as shown below:

To optimize the design by reassigning relationships, Right Click on Full Date and select New Attribute Relationship. Select Related Attribute as Calendar Week and Relationship type as Rigid (will not change over time). Repeat same thing for remaining attributes. Finally Attribute Relation will look like below image:

Deploying Cube Database from BIDS Now its time to deploy the cube at required server. Right click on the project (LearnSSAS in this example) and click properties to open project properties page. Enter Server Name name Server property and Database name in Database property as shown below:

Click OK to save changes. Now right click on the project and click on Process to Build and Deploy the project. You will a message while deploying the database first time.

Click on Yes to proceed. Now you can see Process Database - PreojectName window. Click on Run to continue.

Once the database is deployed and processed successfully, you can see the data through Browser tab or directly through SQL Server Analysis Services. You can also pull cube data in Excel using Excel OLAP Pivot Tables, which is the prefered option used by business managers.

Adding Actions to a Cube in SQL Server Analysis Services 2008

Actions are powerful way of extending the value of SSAS cubes for the end user. They can click on a cube or portion of a cube to start an application with the selected item as a parameter, or to retrieve information about the selected item. Actions haven't been well-documented until now; Robert Sheldon once more makes everything clear.

One of the objects supported by a SQL Server Analysis Services cube is the action. An action is an event that a user can initiate when accessing cube data. The event can take a number of forms. For example, a user might be able to view a Reporting Services report, open a Web page, or drill through to detailed information related to the cube data Analysis Services supports three types of actions:

Report. Returns a Reporting Services report that is associated with the cube data on which the action is based. Drillthrough. Returns a result set that provides detailed information related to the cube data on which the action is based. Standard. One of five action subtypes that are based on the specified cube data: o Dataset. Returns a mutlidimensional dataset. o Proprietary. Returns a string that can be interpreted by a client application. o Rowset. Returns a tabular rowset.

o o

Statement. Returns a command string that can be run by a client application. URL. Returns a URL that can be opened by a client application, usually a browser.

Although the basic steps necessary to implement the various types of actions are similar, the configuration of each one is unique. In this article, I explain how to add a drillthrough action to your cube. The cube I use for my examples is based on the one I describe in the article "Five Basic Steps for Implementing an Analysis Services Database". For that solution, I created the following database components: 1. 2. 3. 4. A data source that points to the AdventureWorksDW2008 database on a local instance of SQL Server 2008. A data source view that includes the tables shown in Figure 1. Database dimensions based on each dimension table in the data source view. A cube based on the database dimensions as well as on the two fact tables in the data source view.

Figure 1: Default diagram from the Sales data source view

Be sure to refer to the article mentioned above for more details about the solution. The article explains how to create the cube necessary to support the action I describe in this article. You can also refer to SQL Server Books Online for more information about how to implement an Analysis Services database and its cubes. Once youve created the database, youre ready to add actions to your soluti on.

Creating a Named Calculation


The drillthrough action that I describe allows users to view a list of customers associated with aggregated Internet sales. To support this action, well first create a named calculation that concatenates the customers first and last names. You create named calculations in the data source views that you reference in your dimensions and measure groups. In this case, well update the DimCustomer table of the Sales data source view. Open the data source view in Business Intelligence Development Studio (BIDS). In the Tables pane of the data source view design surface, right-click the DimCustomer node, and then click New Named Calculation. Name the column FullName and provide a description. In the Expression text box, add the following expression: FirstName + ' ' + LastName The Create Name Calculation dialog box should now look similar to the one shown in Figure 2.

Figure 2: Creating a named calculation on the DimCustomer table

Once youve added the named calculation, you can reference it in your dimensions and cubes as you wo uld any other column in a data source view. For our drillthrough action example, be sure to update the Customer dimension to include the FullName column, and process the cube as necessary so the named calculation will be available to your action.

Creating a Drillthrough Action

To add a drillthrough action to a cube, open the cube in BIDS. On the Actions tab of the cube designer, click the New Drillthrough Action button. A new form is displayed in the design pane, as shown in Figure 3.

Figure 3: Adding a drillthrough action to an Analysis Services cube

The first thing to do is to give the action a name. I used Customer drillthrough, but you can use whatever you think is appropriate. Next, select Fact Internet Sales from the Measure group members drop-down list. Our action will be based on the aggregated totals for Internet sales. The next property, Condition, is a Multidimensional Expressions (MDX) statement that returns a Boolean value. Although this property is optional, we will create an expression to ensure that the action can be triggered only when a cell contains a value. In other words, if there are no sales for a particular category of cube data, the user should not be able to drill down to an empty dataset. To ensure that the drillthrough action applies only to those aggregated totals that have sales, add the following expression to the Condition dialog box:
[Measures].[Sales Amount] > 0

As you can see, the Sales Amount measure must contain a value greater than 0 for the action to be available to the user.

The next property that must be configured for the action is Drillthrough Columns. In this case, you simply select the dimension and its columns that you want returned by the drillthrough action. For our example action, well use the FullName attribute (based on the named calculation) in the Customer dimension. Later, you can add additional attributes or measures to see how they work.

Configuring Additional Properties


If you refer back to Figure 3, youll notice that theres a set of down arro ws for additional properties. Click those arrows to access the properties. The first additional property, Default, is included for backward compatibility. It has to do with how drillthrough actions are evaluated when a DRILLTHROUGH statement is executed by a client application. You can leave its value as False. The next additional property is Maximum rows, which determines the maximum number of rows that will be included in the drillthrough dataset. In this case, Ive set the property to 50, but you can set it to whatever number you think appropriate. The Invocation property determines when the action should run. The default value, Interactive, specifies that the action will run when the user chooses to run the action. However, you can set the property to Batch to indicate that the action should run as part of a batch operation, or you can set the property to On Open so the action runs when the cube is first opened. For our example, well stick with Interactive. The next property, Application, is the name of an application that can run the drillthrough action. You can use this property to identify which client application most commonly uses this action or to display icons next to the action in a pop-up menu. However, the property does nothing but provide a recommendation to the client about which application to use. It does not control access to the action. In this case, well leave this property blank. For the Description property, simply type in a description for your action. I used Describes the action, but you can type in any description you want, or not include a description at all. The Caption property determines what text is displayed when referencing the action. The caption can be a simple string or it can be an MDX expression. For our e xample, well use the following MDX expression:
"Drillthrough to " + [Territory].[Sales Territory Region].CURRENTMEMBER.MEMBER_CAPTION + " customers"

The expression concatenates two strings with the current sales territory region. For example, if the region is Northeast, the caption will read Drillthrough to Northeast customers. The final property is Caption is MDX. If the Caption property is an MDX expression, then the Caption is MDX property should be set to True. Otherwise, it should be set to False. We, of course, must go with True. Your drillthrough action form should now look similar to the one shown in Figure 4.

Figure 4: Configuring a drillthrough action in an Analysis Services cube

After youve configured all the properties for your drillthrough action, you should save and process your cube. You can then use the Browser tab of the cube designer to view the action you just created.

Viewing the Drillthrough Action


To test the drillthrough action, youll want to set up the browser with cube data. Take the following steps on the Browser tab of the cube designer: 1. 2. Drag the Sales Amount measure from the Fact Internet Sales measure group to the Detail Fields Here section of the browsing surface. Drag the Sales Territory Region attribute of the Territory dimension to the Drop Column Fields Here section of the browsing surface.

3. 4.

Drag the Calendar Year attribute from the Order Date dimension to the Drop Row Fields Here section of the browsing surface. Drag the Sales Territory Country attribute from the Territory dimension to the Drop Filter Fields Here section of the browsing surface. Clear the All checkbox on the filter, and then check the United States check box.

Your browsing surface should now look similar to the one shown in Figure 5.

Figure 5: Browsing sales data based on the sales territory and calendar year

Right-click one of the cells that contains aggregated sales amounts to bring up the context menu. The menu should include an option for being able to drill through to the customers. For example, when I right-click the cell for 2003 sales in the Central region, my context menu includes the option Drillthrough to Central customers, as shown in Figure 6.

Figure 6: Verifying that the drillthrough option has been added to the context menu

If I were to right-click a cell that shows no aggregated totals, such as 2001 sales for the Northeast region, the drillthrough option would not be available in the context menu. Thats because we included the MDX expression in the Condition property to make the action available only if there are sales. When you click the drillthrough option, a dialog box appears and displays the list of customer names. These are the customers who made purchases in the specified region and year. Figure 7 shows the customers in the Central region who made purchases in 2003.

Figure 7: Viewing the customer names for aggregated sales totals

As you can see, weve included only the names, but we could have included other informat ion, such as birth dates or annual salaries. Better still, we could have included the Sales Amount measure so we see the amount for each sale. This would have made each row unique, rather than simply having duplicate names like we have now. Indeed, theres a great deal of flexibility in how you design your drill through actions. By setting up the data source views to support the actions and then implementing the actions with the details you want to include, you can provide users with a variety of information that allows them to dig deeper into their cube data. And drill through actions are only one type of many. You can launch reports, open Web pages, run applications, and a number of other tasks. Be sure to check out SQL Server Books Online for more information about each one of them.

How To Define Measure Group Partitions in SQL Server Analysis Services SSAS

Partition Benefits:
Better Query Performance: Cube partition is a powerful mechanism for improving query performance. Queries that summarize data over 10 years could take considerably longer than those that only search through the current year data. If we have proper partitions then SSAS only has to scan a small subset of data to return query results hence dramatic performance improvements compared to queries running against a cube with a single partition. Minimize downtime: Cube partitioning supports reducing downtime associated with cube processing. In almost all the cases, a portion of data warehouse is volatile and needs to be processed often. However other portions are relatively static. For example, in a sales cube, we need to change the current year's data nightly, but sales from previous years might change only occasionally - in case if account for merchandise returns and exchanges. If your warehouse tracks last 10 years salesthen processing only the current partition may be 10 times quicker than processing the entire cube.

Aggregations benefits: The partition queried frequently could benefit from additional aggregations, which in turn could improve performance. Partition(s) that are used less can be processed less frequently with considerably fewer aggregations. Customized storage and processing settings: Frequently accessed partitions might benefit from proactive caching and ROLAP storage. On the other hand, other forms of storage and processing might be better for less frequently queried partitions. Distributed query and processing load: SSAS allows you to create remote partitions - a remote partition resides on a server different from its parent cube. This way the queries that affect the remote partition are processed on a server separate from its parent cube, allowing you to take advantage of additional processing power. Parallel Partitions Processing: SSAS allows processing multiple partitions in parallel on a server that has multiple processors. This can further reduce the total cube processing time.

Step 1: Edit the project properties by clicking Project, Properties from the top-level menu; set the Deployment Server Edition to Enterprise. Multiple partitions are only available in the Enterprise Edition of SQL Server 2005 so you need to specify the Deployment Server Edition as Enterprise.

Step 2: Double click the Adventure Works cube in the Solution Explorer then click the Partitions tab to display the existing partitions (only the first partition is shown below).

Click on Internet_Sales and edit the Partition Name to Internet_Sales_2001. Step 3: Click the Internet_Sales partition (you should see the entire row highlighted as shown above) to display the partition properties. Click the button in the Source property to display the binding:

Step 4: Change the Binding type from Table binding to Query binding and add the WHERE clause as shown below:

The idea is to change this partition so that it only has orders that were shipped in the year 2001. The ShipDateKey column references the TimeKey column in the DimTime table (Time dimension) in the AdventureWorksDW database. Run the following query to determine the ShipDateKey for the date 2001-12-31 and you will see that 184 is the TimeKey value: SELECT TimeKey FROM DimTime WHERE FullDateAlternateKey = '2001-12-31' Step 5: Click New Partition (see hyperlink in Step 2 above) to add another partition to the Internet Sales measure group. This will launch the Partition Wizard. Select the dbo.FactInternetSales table under Available tables:

Step 6: Click Specify a query to restrict rows and add the WHERE clause as shown below:

The idea is to set this partition so that it only has orders that were shipped in the year 2002. If you query the DimTime table you will find that the TimeKey value for 2002-12-31 is 549. Step 7: Accept the defaults on the Processing and Storage Locations dialog:

Note that selecting Remote Analysis Services data source for the Processing location is a scale-out feature where you could actually process this partition on another SSAS server. Step 8: Complete the Partition wizard; fill in the dialog as shown below:

Repeat steps 5 through 8 to create and configure partitions for the years 2003 and 2004. Step 9: Process the cube; right click on the Adventure Works cube in the Solution Explorer and select Process from the context menu. Accept the defaults on the Process Cube dialog; click Run (Run button not shown below):

SSAS 2008-Perspectives
When creating a cube in SSAS with the fact and dimension tables, it is possible that the Measures in the cube could belong to different parts of business. To elaborate on this , it is possible that the Cube could have Sales related measures, Customer related measures and Product related measures. When the cube is deployed and is being viewed by business users, it is possible that certain business users would like to focus on the measures to their business area. In order to achieve instead of having cubes split into smaller cubes based on business function, there is a feature called Perspectives available in SSAS 2008. Once the cube has been created and related dimensions have been added, the different perspectives can

be created. In the screen shot below, the Perspectives tab is highlighted (this is in BIDS/Visual Studio 2008).

In the Perspectives, initially one gets to see the default perspective which is a view of the whole cube with all the measures and all the dimensions. In order to create a new Perspective, one has to click the New Perspective icon nest to the process icon in the toolbar.

First name the new perspective and start working downwards to start choosing/Checking the Measures needed to be shown for this perspective, likewise do the same for the dimensions.

SSAS 2008: New Cube Aggregations tab


The November CTP of SQL Server 2008 was released on the connect MSDN Downloads site at the end of last week and when you open up a cube in BIDS you will see a new tab for aggregations. I figured I might give you a bit a walk through what you can expect from this new tab.

What this tab does is to let you see all the aggregation designs that relate to a given measure group. It also lets you manage which partitions are using a particular aggregation design. As with the other Analysis Services designers, the new AMO warnings are also surfaced in the aggregations tab which lets you see if there are any basic issues with your aggregations. Such as a particular design no being referenced by any partitions

Or even an AggregationUsage property not being set properly.

Right-clicking on an aggregation design gives a number of options including "Design New Aggregations", "Usage Based Optimisation" and "Assign Aggregation designs".

When you start up the "Design Aggregations" Wizard you can now easily select which aggregations a particular design is to apply to.

One of the coolest additions to the aggregation design wizard is the following screen which shows you the aggregation usage setting for all the attributes and gives you the ability to change them.

The objects count screen appears largely unchanged.

As does the core Aggregation Options screen.

At the end of the whole process you get to give your design a name. I would suggest that you might want to think about including an indication of the design options that you used. (eg "30 pcnt", "upto 150Mb", etc. ) You can see a property for the aggregation level when you view the properties of the aggregation design, which is where I thought information like this would be recorded, but that property did not appear to update (maybe this will change in a future build). But if you have a couple of different aggregation designs, this would let you see at a glance, which was which.

When you right click an Aggregation Design and choose the option to Assign Aggregations, you get the following dialog box. This gives you a very easy way to apply a given aggregation designs to a group of partitions.

You might also like