olap data cubes in sql server 2008 r2 analysis services - el aprendiz de brujo

Upload: naveen-kumar

Post on 03-Jun-2018

233 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    1/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx

    Iniciar sesin| HAZTE MIEMBRO!| Ayud

    El aprendiz de brujoEl blog de Luis Miguel Blanco con hechizos, conjuros y sortilegios varios sobre la plataforma .NET y

    Business Intelligence

    OLAP Data cubes in SQL Server 2008 R2 Analysis Services

    (The spanish version of this article was previously published in dNM+, issue 77)

    It is an undeniable fact that in recent times, the volume of data that organizations must managehas soared. Analyze so much data; in order to make strategic decisions has become a realproblem. In this article we will make an introduction to OLAP data cubes in SQL Server 2008 R2Analysis Services, a powerful tool that can transform vast amounts of data into usefulinformation.

    The excessive increase of the volume of data into information systems of a company, without

    proper organization and structure, can have negative effects such as slow in their status analysior worse, lead to inappropriate strategic decision making, since having millions of recordsdistributed across multiple heterogeneous data sources (SQL Server and Access databases, flatfiles, Excel spreadsheets, etc..), need not be synonymous in all cases of a system that providesquality information.

    To solve such problems we have the so-called Business Intelligence (BI) tools, and in the case ware working with SQL Server, one of its main components: SQL Server Analysis Services (SSAS)allow us to create a data cube, an element by which to generate information to analyze the stateof the company from all its data sources.

    Conceptual

    From a conceptual perspective, a data cube is one more part into the gear of an informationsystem called data warehouse. The cube is provided with internal machinery that can process higvolumes of data in a relatively short period of time, and whose goalis always to obtain anumerical result (amount of sales, expenses, number of products sold, etc.). These results maychange depending on one or more filters that apply on the cube. The response time is minimalbecause the cube processing engine precalculates the possible combinations of results that theuser can request. The numerical results obtained are called measures, while the elements used tosort / filter information are called dimensions.

    Represented graphically, a data cube is shown as the geometric shape which takes its name,

    horizontally and vertically partitioned into a series of divisions that give rise to multiple cells, whicidentify each of the possible outcomes of the measures, obtained by the intersection in each cellof the dimensions that make up the cube. Next figure shows such a graphical representation of acube, with sales information by product, employees and currency. On the cube sides are placedthe dimensions, whose cross produces numerical results in the cells.

    http://www.dnmplus.net/articulos/cubos-de-datos-en-sql-server-2008-analysis-services.aspxhttp://geeks.ms/blogs/lmblanco/default.aspxhttp://geeks.ms/login.aspx?ReturnUrl=%2fblogs%2flmblanco%2farchive%2f2012%2f07%2f31%2folap-data-cubes-in-sql-server-2008-r2-analysis-services.aspxhttp://geeks.ms/user/CreateUser.aspx?ReturnUrl=http://dev.communityserver.com/r.ashx?K&siteurl=weblogs.weblogpostNamehttp://www.dnmplus.net/articulos/cubos-de-datos-en-sql-server-2008-analysis-services.aspxhttp://geeks.ms/blogs/lmblanco/default.aspxhttp://dev.communityserver.com/r.ashx?K&siteurl=weblogs.weblogpostNamehttp://geeks.ms/user/CreateUser.aspx?ReturnUrl=http://geeks.ms/login.aspx?ReturnUrl=%2fblogs%2flmblanco%2farchive%2f2012%2f07%2f31%2folap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx
  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    2/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 2

    Watching the previous figure, the reader may think that the number of dimensions in a cube islimited to those we represent through that geometric shape. Nothing is further from reality, sinca cube can withstand a high number of dimensions, which loosely cover the requirements of theinformation to be obtained.

    We can find additional information about the conceptual aspects in a series of articleson datacubes in SQL Server, previously appeared in this publication.

    Main elements in a data warehouse

    As mentioned above, a data cube is one of the pieces of a more complex architecture: the datawarehouse, in which creative process involved several components, which are responsible to takethe original data in the rough and polish it until it becomes in information ready for analysis. Nextfigure shows a diagram where we can see the phases of this transformation process.

    http://www.dnmplus.net/articulos/sql-server-analysis-services-hola-cubo-i.aspx
  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    3/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 3

    Broadly depicted, this process performs, in first place, an operation of extraction, processing andloading data from source origin, located in the operational area, to a database located in theintegration area, using SQL Server Integration Services (SSIS) packages, which also performeddata cleaning tasks.

    Then we would pass to the cube construction phase, which we will develop using SQL ServerAnalysis Services (SSAS). Finally, we reach the stage of cube query by end users, using severalproducts such as SQL Server Reporting Services (SSRS), Excel, etc.

    Physical elements. Fact and dimension tables

    At the physical level, to build a data cube we need a database containing a table called fact table,whose structure is formed by a series of fields, called measurement fields, from which we obtainthe cube's numerical results; and on the other hand, a set of fields called dimension fields, thatwe will use to join with the dimension tables, in order to get filtered results for the severaldimensions integrating the cube.

    The other main foundation in the cube creation is made from the dimension tables. For eachdimension or query / filter category we incorporate into our cube will need a table that will joinwith the fact table by a key field. This dimension table will act as a catalog of values, also calledattributes, which will be used independently or combined with other dimensions, to obtain resultwith greater accuracy.

    Developing a data cube

    Once explained the necessary basics, we enter into the practical part of the article, where we'lldevelop our own data cube. We will focus all our efforts exclusively on the cube creation, without

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    4/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 4

    addressing the extraction, transformation and loading operations, which would be made usingSSIS packages, since the latter are issues that fall outside the scope of this article, pending afuture delivery.

    First, from Windows Start menu we'll launch SQL Server Business Intelligence DevelopmentStudio, which is located in Microsoft SQL Server 2008 R2 program group. This is a special versioof Visual Studio for BI projects development. In the starting dialog we'll selectAnalysis ServicesProjectas project template, giving it the name CuboDatosAdvWorks.

    Then right-click Data Sourcesnode in the Solution Explorer and select New Data Source option,which opens the wizard to create the cube data source, which in our case will be the testdatabase AdventureWorksDW2008 available in CodePlex, whose structure is ready to be used indata cubes design.

    We will leave the default options in the wizard until the connection to the data source step,selecting AdventureWorksDW2008. On reaching the wizard final step will see a summary of thedata source we have created.

    Our next step is to create a view of the data source, allowing us, as his name suggests, define acustom view of the database, including the tables we need to create the cube.

    In this sample cube we'll measure the amount of sales that AdventureWorks company resellershave invoiced. Being possible query / filter the results by currency type in which the sale wasmade, and geographic area where the order was sent. We will use FactResellerSales as fact table

    http://msftdbprodsamples.codeplex.com/releases/view/55926
  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    5/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 5

    and DimSalesTerritory and DimCurrency as dimension tables.

    By right-clicking the Data Source Viewsnode in Solution Explorer, we'll select New Data SourceViewoption, which opens a wizard in which first step we will choose the data source we justcreated. In the second step we'll select the tables just mentioned.

    Once finished this wizard it will display its design window where we see a diagram of the selectedtables, with the existing relationships between them.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    6/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 6

    Building dimensions. Basic dimension

    The next step is to create the dimension that allows us to query / filter the cube information byorder payment currency. Right clicking on the Dimensionsnode of Solution Explorer, we'll select

    the New Dimensionoption, starting the wizard as usual. In his first step Select Creation Methodwe'll leave the default option Use an existing table. Upon entering step Specify SourceInformation, three drop-down lists allow us to configure the information to be obtained for thedimension: Main tableto choose the table that use in the dimension: DimCurrency; Key columnto indicate the primary key; and finally, Name column, selecting CurrencyName field, whichidentifies the attribute to be displayed.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    7/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 7

    In the Select Dimension Attributesstep, the wizard will offer Currency Keyas an attribute of thedimension, which we will use, but changing its name to Currency. An attribute is a field, normal ocalculated, belonging to the dimension table that is shown as a label anywhere in the dimensioninvolved as part of a query against the data cube.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    8/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 8

    At the last step we shall give the name Currency to the dimension, finishing the wizard. Thedimension designer will show now with the structure we just created. Among all the properties othe attribute Currency, the most important are Name, which contains the name that will appear iqueries against the cube; KeyColumns, which contains the key field in the table that relates to thfact table, and NameColumn, containing the field of the table that shows the attribute's value.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    9/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 9

    In case we need to add more attributes to the dimension, just drag and drop fields from the tabin Data Source Viewpane to the Attributes pane of the designer.

    When attribute creation is finished, we'll process the dimension by clicking the Process button onthe toolbar's designer, or through the Visual Studio Build | Processmenu. When the processingdimension is completed, we will click on the designer's Browser tab, where we'll inspect itscontain.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    10/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 10

    Building dimensions. Hierarchical dimension

    In addition to the single level dimensions, as we just saw in the previous section, we can createdimensions that group data on multiple levels, which provide a greater ability to disaggregate thecube information when consulted through a dimension of this type. This element is called adimension hierarchy.

    Let's take DimSalesTerritory table from our Data Source Viewsample project. We can see thatthe combination of SalesTerritoryGroup, SalesTerritoryCountry and SalesTerritoryRegion fieldsallow us to establish several grouping levels.

    Suppose we need to create a dimension based on this table to obtain, starting fromSalesTerritoryGroup field, a hierarchical level display effect.

    To do this, we will create the dimension using the wizard in the way explained in previous section

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    11/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 1

    The default attribute selected by the wizard will correspond to table's primary key:SalesTerritoryKey field.

    Once located in the dimension designer, drag from the table in Data Source Viewpane theSalesTerritoryGroup, SalesTerritoryCountry and SalesTerritoryRegion fields, and drop on theAttributes panel of the same designer.

    Then drag the Sales Territory Group attribute to the Hierarchies pane, which will create a newhierarchy. We'll change its default name by Sales Territory. Also in this hierarchy will drop the

    Sales Territory Country and Sales Territory Region, noting that next to the hierarchy nameappears a warning icon which informs us that relationships between the hierarchy attributesaren't properly created, which can negatively affect the dimension processing.

    To solve this problem we will click theAttribute Relationshipstab, where we see the relationshipsbetween attributes automatically created by the designer.

    These relationships, however, are not valid for our purposes, so we'll select their representingarrows in the diagram and delete them. To create the new relationships drag from sourceattribute to destination, to leave them as see in next figure.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    12/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 12

    Before dimension processing let's back to the Dimension Structuretab to verify that the warnin

    is gone. On the other hand we'll select all attributes of the Attributes panel, assigning the Falsevalue on his property AttributeHierarchyVisible, so we'll get independent attributes are notshown, since what interests us here is to explore only the hierarchy. Next figure shows thedimension result, with all elements of the hierarchy expanded.

    Cube Building

    We reached the final stage in the development of our sample project: building the data cube. Wewill begin by right-clicking the Cubes node in Solution Explorer and selecting theAdd Cubeoption, which will open the creation wizard, leaving the default values until the Select Measure

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    13/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 13

    Group Tablesstep, which as its name suggests, it asked us to select the table containing thefields that we use as measures for the cube, i.e. the fact table, which in this case will beFactResellerSales.

    Clicking Next, go into the Select Measuresstep, where we have to select the fields that serve ascube measures. The goal of this cube is to ascertain the sales amount made by resellers,therefore, we'll select only the SalesAmount field.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    14/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 14

    The next step prompts us to select the dimensions that will be part of the cube. It automaticallydetected the dimensions created by us earlier, which already are offered selected by default.

    The wizard performs then a search in the fact table to find a field that could also be capable ofbeing treated as a dimension. Since we don't need this feature, we'll uncheck the selection of thefact table as source for the creation of dimensions.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    15/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 15

    And now the final step, where we will give the name VentasDistribuidores to the cube, ending thwizard.

    As a result the cube designer displays itself, showing various key elements, such as thedimensions pane, table diagram, measures, etc.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    16/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 16

    In the Measures pane appears the measure selected in the wizard, but we'll change its name toImporte Ventasin properties window. In this same window we can watch the name, aggregatefunction used to calculate the measure, used table field, format string, and so on.

    For the measure to appear correctly formatted, in addition to assigning a value to theFormatString property, in the cube properties we have to assign the value Spanish (Spain)to thLanguage property.

    Finally, before we can see the cube, as we did with the dimensions, we must process it by clickingthe Process button, which opens the dialog box cube processing where we'll click the Run button

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    17/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx 17

    Once the cube has been processed, we can see its contents by clicking on the Browser tab. In thMeasure Grouppane we'll expand the Measures node up to the Importe Ventas measure, whichdrag into the central area of the display. Then drag the SalesTerritory dimension to the display'sleft margin. We can right click on this dimension, selecting Expand Itemsoption, resulting in adisplay of the dimension elements. Finally drag the Currency dimension to the upper margin. As result we get a data grid where each cell displays the measure for the intersection of thedimensions placed in columns and rows of data display.

  • 8/13/2019 OLAP Data Cubes in SQL Server 2008 R2 Analysis Services - El Aprendiz de Brujo

    18/18

    2/12/14 OLAP Data cubes in SQL Server 2008 R2 Analysis Services - El aprendiz de brujo

    Conclusions

    In this article we have made an introduction to the development of data cubes with SQL Server

    2008 Analysis Services, a component of SQL Server product family intended to provide businessintelligence solutions that exploit the analytics potential that lies in data's company. Thepossibilities and power of this tool are enormous, and we encourage the reader to implementthem.

    Published 31/7/2012 21:45 por Luis Miguel BlancoArchivado en: SQL Server,SQL Server 2008 R2,Business Intelligence,Data WarehouseComparte este post:

    Comentarios

    Tuesday, September 11, 2012 9:46 PM por El aprendiz de brujo#SQL Server 2012 Analysis Services Tabular Models

    (The spanish version of this article was previously published in dNM+ , issue 93) The recent SQLServer

    Monday, September 17, 2012 9:48 PM por El aprendiz de brujo#PowerPivot, DAX and Excel. Business Intelligence for all audiences

    (The spanish version of this article was previously published in dNM+ , issue 83) PowerPivot is atechnology

    http://geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx#206774http://geeks.ms/blogs/lmblanco/archive/2012/09/17/powerpivot-dax-and-excel-business-intelligence-for-all-audiences.aspxhttp://geeks.ms/blogs/lmblanco/archive/2012/07/31/olap-data-cubes-in-sql-server-2008-r2-analysis-services.aspx#206711http://geeks.ms/blogs/lmblanco/archive/2012/09/11/sql-server-2012-analysis-services-tabular-models.aspxhttp://geeks.ms/blogs/lmblanco/archive/tags/Data+Warehouse/default.aspxhttp://geeks.ms/blogs/lmblanco/archive/tags/Business+Intelligence/default.aspxhttp://geeks.ms/blogs/lmblanco/archive/tags/SQL+Server+2008+R2/default.aspxhttp://geeks.ms/blogs/lmblanco/archive/tags/SQL+Server/default.aspxhttp://geeks.ms/members/lmblanco/default.aspx