Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Developing a ssrs report using a ssas data source


Published on


Published in: Education, Technology

Developing a ssrs report using a ssas data source

  1. 1. source: -- printed: 6/5/2013 11:29:35 PMDeveloping a SSRS report using a SSAS Data SourceWritten By: Scott Murray -- 6/11/2012ProblemAfter designing several SSRS reports based on regular relational databases, your boss would now likeseveral new reports to be designed and rolled out to production based on your organizations SSAS OLAPcube. How do you get started with designing a report based on a cube?SolutionThe creation of an OLAP SSAS report is similar to other SSRS report development once you get to theactual report layout. However, designing your data sources and datasets varies quite a bit from normalrelational database data sources and datasets.The first step in creating a new OLAP based SSRS report is to create a New Project as noted in the belowfigure. Of course, you could also add a new data source, dataset, and report to an existing project;however in our example, we will utilize a new project with a new report.First you will want to create a new Report. We are going to utilize data sources and datasets which residewithin the report as opposed to utilizing shared datasets and data sources. To Start the New ReportWizard, Right click on Reports, and select Add New Report.
  2. 2. The New Report Wizard opens and the first step in the wizard allows for the creation of a data source. Youwill fill in the New Data Source Name and change the Type to Microsoft SQL Server Analysis Services.Next, select the Connection String Edit button. Fill in your Server Name and then select or type in theappropriate SSAS database name. Be sure to test the connection using the Test Connection.Depending on the roles created for SSAS Cube you are connecting to, you may have to change the accessdetails noted in the Credentials window. In our demo we will use integrated security, so on the ConnectionProperties dialog box, click OK.After setting up your data source and clicking next, you will now create your dataset to be used in thereport. This step requires planning and forethought as to what fields will be displayed on the report andwhat fields will be used to filter the data both when establishing the dataset and during report generationas parameters. These decisions will impact how the data is returned to the design grid and ultimately tothe report itself. In order to define your dataset, click the Query Builder button.
  3. 3. The Query Builder button opens the Query Designer Window as displayed in the below figure.The SSAS query designer has several options and methods that will ultimately affect your end report.Initially, you will notice that you have the ability to drag and drop both dimensions and measures onto theresults grids. You will additionally notice how the results grid actually flattens your datasets. You can add
  4. 4. entire dimensions in one motion by clicking and dragging the Dimension folder onto the results area. Also,the same process works for hierarchies, although you can also add individual attributes from the hierarchyif needed.There are several buttons in tool bar of the Query Builder that should be noted. For full descriptions of thebuttons, please see Analysis Services MDX Query Designer User Interface at The Show Empty Cells works this same as theMDX Non Empty clause; basically it shows / hides non empty cell values. The Auto Exec button turns onand off the auto execution of queries as you drag and drop dimensions, measures, hierarchies, andattributes onto the results pane. As the results get larger and more complex, it could take longer andlonger for the query results to return. The Show Aggregates button again toggles the view of aggregateson and off. Last, the Add Calculated Members button allows for the addition of calculations at the querylevel. These calculated members could also potentially be added at the report level instead.Furthermore, the query designer contains a filter grid in the upper half of the design area. This filter areaserves several purposes:1. Acts as a method to filter the dataset at the query level.2. Allows for the easy creation of filters which can also act as parameters. (see additional detailsabout parameters below).Filters can either be individual attributes or individual parts hierarchies.
  5. 5. The above example filters the dataset at the query level; basically, the query will be restricted to onlythose items who Calendar Year equals CY 2003. You will also notice that the parameter box is not checkedin this first example. Last, since the Auto Exec button is toggled on, the query results will display CalendarYear 2003 data. At this point, we will complete the rest of the wizard setup to create a basic report. Laterin our tip, we will discuss the parameter option. Going back to change this option later will also allow us toreview making changes to the Data Set after completing the Wizard. Clicking Ok on the Query Builderscreen returns you to the Report Wizard with the MDX query now being displayed in the Query String asnoted in the next figure. Furthermore, notice that the Calendar Year filter is part of the MDX query text.
  6. 6. The report type is selected on the next screen; a matrix report will be used in this demo.We will complete the report by placing Year and Quarter in the Column group, Country in the Row group,and Internet Group Profit and Internet Order Count in the Details area.Next, accept the Matrix Style of Slate.
  7. 7. Now, finish out the report by completing the Report Name.The initial SSAS Report design is now complete. A preview of the design and end report is displayed in thenext two figures.
  8. 8. Of course to completely finish the report you may want to complete some formatting. As such, thenumeric fields were immediately formatted to display commas and no decimals.Our next step is to adjust the dataset filters and replace the hard coded filter for the Calendar Year to aparameter based filter where the report consumers can select which year to display. As noted in the nextfigure, expand the Datasets folder, and then right click on DataSet1, and select Query to display theQuery designer..
  9. 9. Now, change the Filter Expression to include CY 2002, CY 2003, and CY 2004. Also, check the Parameterscheck box.Adding these changes now creates a parameter for the Calendar Year which is displayed by expanding theParameters folder, as shown in the following figure.
  10. 10. Checking the parameter box also adds a hidden dataset, that can be shown by right clicking Datasets andselecting Show Hidden Datasets.After making this change to add the Calendar Year parameters and previewing the report, as shown in thenext figure, you will notice two Alls, Select All and All Periods, appear in the drop down list. The first All isdriven by the Report Server MultiParameter option while the second is driven from the MDX query thatSSRS runs to populate the Parameters list.
  11. 11. To alleviate this situation, we have several options. Either we can adjust the MDX query or we can add afilter to the dataset to remove the All Member from the results. Using the first option, right click on theDate Calendar Year hidden dataset (after using the technique noted above to show the hidden data set),and then select Query. The first figure below displays the current query. Changing the highlighted word,ALLMEMBERS to CHILDREN adjusts the query to display only the Children of the Calendar Year list and notthe All member option.
  12. 12. Alternately, we can filter the dataset using the filter dataset method; right click on the Date Calendar Yearhidden dataset (after using the technique noted above to show the hidden data set), and then selectQuery Properties. The first figure below displays the current query with its related result set. Within theDataset Properties Window, clicking on the Filter Option, allows us to filter on any of the fields beingreturned from the query. In this particular instance, I see that we can easily exclude the All Periods item,by using a filter of ParameterLevel> 0 which is displayed in the second figure below.Now when we run the report, as displayed in the next figure, only the individual years are displayed whichprovides for a much cleaner option for the report consumers.
  13. 13. Conclusion-Creating a Cube Based Reporting Services ReportIn this tutorial, we reviewed the process of creating a Report Services report based on a SSAS OLAP cube.We learned about the process of creating an initial report using the Create Report Wizard and identifiedthe specific places where attention needs to be focused during the wizard steps. In particular we need topay close attention to the fields we place on the results grid along with the attributes and dimensions usedin the filter area. Furthermore we addressed adding a parameter to a report and specifically adjusting theparameter query or filter to properly display the parameter options.Next StepsJen Underwoods SQL Saturday Presentation on SSAS data sources. out these related resources:o SQL Server Reporting Services Tutorialo Reporting Services Development Tips
  14. 14. source: -- printed: 6/5/2013 11:33:54 PMSQL Server Reporting Services Using Multi-valueParametersWritten By: Scott Murray -- 1/21/2013ProblemAfter working with SQL Server Reporting Services ( SSRS ) for a time, eventually a report user willwant to select more than one value for a parameter. How does SSRS handle multi-value parameters?SolutionAllowing users to select multiple values from a parameter list is a great feature in SSRS; it allowsreport consumers more selection flexibility when running reports. However, how the parameters arepassed to the dataset (or report object filters if used) varies depending on if the datasource is based onT-SQL embedded in a dataset within a report or if the data is passed via a stored procedure.Furthermore, once the report is run, a good practice is to display the selected parameter listsomewhere within the report. The below instructions will convey the various techniques needed toutilize multi-value parameters. Finally, we will cover using a filter based multi-value parameters.Embedded ParametersOf the various options, passing multi value parameters to an embedded query is the less complex ofthe two methods. Utilizing this method, the report designer just needs to write a normal query, andutilize the "IN" key word in the criteria section of the query and then refer to the multi-value parameterusing the @parameter name syntax within the parentheses portion of the IN statement. Using anAdventureWorks database and report example, the below code, inserted into a report dataset, notatesthe required syntax. This syntax should be somewhat standard to many of you who write T-SQL on adaily basis.SELECT P.FirstName + + P.LastName AS Employee,DATEPART(Year, SOH.OrderDate) AS Year,DATEPART(Month, SOH.OrderDate) AS MonthNumber,DATENAME(Month, SOH.OrderDate) AS Month,SUM(DET.LineTotal) AS SalesFROM Sales.SalesPerson AS SPINNER JOIN Sales.SalesOrderHeader AS SOH ON SP.BusinessEntityID = SOH.SalesPersonIDINNER JOIN Sales.SalesOrderDetail AS DET ON SOH.SalesOrderID = DET.SalesOrderIDINNER JOIN Sales.SalesTerritory AS ST ON SP.TerritoryID = ST.TerritoryIDINNER JOIN HumanResources.Employee AS E ON SOH.SalesPersonID = E.BusinessEntityIDINNER JOIN Person.Person AS P ON P.BusinessEntityID = SP.BusinessEntityIDWHERE (YEAR(SOH.OrderDate) IN (@ReportYear))GROUP BY P.FirstName + + P.LastName,SOH.SalesPersonID
  15. 15. ,DATEPART(Year, SOH.OrderDate),DATEPART(Month, SOH.OrderDate),DATENAME(Month, SOH.OrderDate)Next we will setup the parameter to accept multiple values. In the below example, a parameter called@ReportYear is already created, so right mouse clicking on the parameter (Report Year in the belowexample ) and selecting Parameter Properties will open the Report Parameter Properties window. Nowcheck the Allow multiple values option. If you are setting up a new parameter, right mouse click onParameters and then select New Parameter.Subsequently, we will define the values to be used for our parameter list; this list will be the valuespresented to the report consumer. First, we define a dataset using the following simple query togenerate a list of values for the ReportYear field.SELECTYear(SOH.OrderDate) AS YearFROMSales.SalesOrderHeader AS SOHGROUP BYYear(SOH.OrderDate)
  16. 16. ORDER BY SOH.YearFinally, we set the dataset, Year_Lookup, to be used for the available values for the ReportYearparameter, and note below.Now, the parameter is setup to accept multiple values. The setup required several steps includingsetting up our main report query to accept a parameter using the IN criteria, changing the allowmultiple values option on the parameter properties, and last, generating a list of available values, inthis example using another query. The end result is two fold. First, the report consumer now sees
  17. 17. check boxes next to each parameter item which allows the user to select multiple values, as displayedbelow. Second, the report displays only the years selected.Finally, the report data displays the years selected.You may notice in the above figure that the title shows #Error after Sales Report for:.This fieldreferences the @ReportYear parameter; when this parameter was just a single value, it displayedcorrectly. However, now that the parameter is multiple values, SSRS is unable to display a value.Fortunately, the SSRS Join function can be used to display all the values selected and separate themwith a fixed symbol. For this report we will break up the years with an &. The exact formula used is asfollows:=JOIN(Parameters!ReportYear.Value, " & ")The report with the JOIN function utilized is displayed below.
  18. 18. Multiple Value Parameters and Stored Procedure Based DatasetsUsing stored procedures as the basis for SSRS datasets offers many advantages including potentialreuse by other reports and potential performance advantages. However, multi-value parameters do notwork well when getting passed to a stored procedure. Embedded SQL datasets noted above handle theparsing of the multiple values used in the IN criteria. To the contrary, when the multiple values arepassed to a stored procedure, all the values are conveyed as one value.The ReportYear parameter in our example report, for instance, would get passed as one value,"2006,2007,2008" which, of course would return no rows. Fortunately, we can use a string splitterfunction as part of our stored procedure to break up the years into multiple values. We will once againturn to using a Tally table by Jeff Moden; please see this article on using the Tally table to parse outthe values, am not going to repeat Mr. Modens code in the article, since it would be beneficial for you tounderstand what it can and cannot do. We will however use this function in dataset stored procedurewhich is noted below. Please make the following notes about the stored procedure. First we are passingin the concatenated multi-value parameter as a single entity and we use a varchar parameter (whichmust be large enough to accept the maximum length of all the parameters which might be selected).Next using the splitter function, the values are parsed out and placed into a temporary table,#YEAR_LIST. Last, the year criteria is moved from being part of the where clause to being part of thejoins.SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: Scott Murray-- Create date: 01/01/2013-- Description: Sales by year query with parameter breakout-- =============================================ALTER PROCEDURE dbo.usp_Sales_by_Year@ReportYearvarchar(50)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;--Parse values into table which will be an inner join on main data query.SELECT ItemINTO #YEAR_LISTFROMdbo.DelimitedSplit8K(@ReportYear,,)
  19. 19. --Main DatasetSELECT P.FirstName + + P.LastName AS Employee,DATEPART(Year, SOH.OrderDate) AS Year,DATEPART(Month, SOH.OrderDate) AS MonthNumber,DATENAME(Month, SOH.OrderDate) AS Month,SUM(DET.LineTotal) AS SalesFROM Sales.SalesPerson AS SPINNER JOIN Sales.SalesOrderHeader AS SOH ON SP.BusinessEntityID = SOH.SalesPersonIDINNER JOIN Sales.SalesOrderDetail AS DET ON SOH.SalesOrderID = DET.SalesOrderIDINNER JOIN Sales.SalesTerritory AS ST ON SP.TerritoryID = ST.TerritoryIDINNER JOIN HumanResources.Employee AS E ON SOH.SalesPersonID = E.BusinessEntityIDINNER JOIN Person.Person AS P ON P.BusinessEntityID = SP.BusinessEntityIDINNER JOIN #YEAR_LIST AS YEARLIST ON YEAR(SOH.OrderDate) = YEARLIST.Item --Use joininstead of where clause--WHERE (YEAR(SOH.OrderDate) IN (@ReportYear))GROUP BY P.FirstName + + P.LastName,SOH.SalesPersonID,DATEPART(Year, SOH.OrderDate),DATEPART(Month, SOH.OrderDate),DATENAME(Month, SOH.OrderDate)ENDGOCertainly other methods exists to handle the parsing and include using the function in the where clause(I would avoid this method as I would not want to call this function for every row!). Alternatively, youcould use a cross apply to match the years with the dataset. The final report utilizing the storedprocedure methods is displayed subsequently.Using Filters with Multiple Value ParametersOne last alternative involving the use of parameters pertains to dataset or object filters. Using filters atthe object level, for example on a tablix, actually allows the same "larger" dataset to be used formultiple purposes while at the same time filtering the individual report parts based on a particularcriteria. This setup can be advantageous in using a single dataset for all the report data; however, youalso need to be careful about retrieving "very large" datasets while only using very small sets of thedata. To setup a filter, first select the object in question, and then right mouse, click and selectproperties as illustrated below.
  20. 20. On the properties window, select the Filter window, and click add. Select the "field" or expression thatis to be filtered, and then select the "In" Operator. Last, click on the fx expression builder button to theright of the value field to open the expression builder box.
  21. 21. As shown in the below illustration, within the filter expression box, click on Parameters under Category,and then double click on ReportYear Under years. What appears in the expression value box includes"(0)" at the end of name. This zero actually means retrieve the parameter in ordinal position 0 (ie thefirst parameter of the selected parameters). As you are probably realizing, that is not what we wouldlike to filter on; we want to filter on all the parameter values selected. The trick to make the filter work,is as easy as removing the "(0)" from the expression.Finally, the filter expression value actually should look as displayed below.
  22. 22. Now, the resulting report using a multiple value tablix filter is illustrated below.ConclusionMultiple value parameters are a wonderful tool within SSRS; their methods in practice, though, variesdepending on their usage within embedded T-SQL, within stored procedures, or as part of an SSRSobject filter. Embedded T-SQL is somewhat easier to use, however, the query can not be easily shared;to the contrary, using a stored procedure offers the ability to reuse a query (and other set based andlogic structures), but you must parse parameter. Using a multiple value parameter with an object filteris also easy to implement as long as you know how to implement the parameter values in the filter.Last, it is often beneficial to display the parameters selected by the report consumer; the join functionin SSRS allows you to display the parameter list easily in the report header or body.Next StepsSingle-Value and Multi-value Parameters (Report Builder and SSRS)-- Dynamic Report Filters in SQL Server Reporting Services SSRS -- parameters and using default parameter values in SSRS reports -- control and setup of SSRS report parameters from a web page -- out this additional tip on multi-parameter SSRS reports
  23. 23. source: -- printed: 6/5/2013 11:35:50 PMBuilding Key Performance Indicators (KPIs) withPowerPivotWritten By: Brady Upton -- 3/5/2013ProblemWhile PowerPivot isn’t necessarily “new technology” I think businesses are trying to move towards itbecause Excel savvy end users can create their own reports without tying up IT resources. KPI’s arejust another addition to PowerPivot that allows users to visually analyze data across millions of rows.In a previous tip I explained how to use PowerPivot with Excel 2013. This tip will focus on creatingcalculated fields and KPI’s in PowerPivot. Check it out.SolutionA KPI (Key Performance Indicator) is a graphical representation that displays progress against apredefined measure or business goal. KPIs make it easier for end users to evaluate the amount ofprogress without reading a bunch of data.If you are new to PowerPivot, try looking over some of these tips first to gain a foundation on whatPowerPivot is and some of the basics of creating dashboards.In this example, I’ll use AdventureWorksDW2012 sample data so you can follow along with me. Thedatabase can be downloaded here.Let’s get started.Enabling PowerPivot in Excel 2013To enable PowerPivot, open Excel, go to File, Options, Add-Ins, select COM Add-ins and click Go. Thiswill open up the COM Add-Ins dialog box. Click “Microsoft Office PowerPivot for Excel 2013” and hit OK.After successfully enabling PowerPivot, the tab should appear at the top of the Excel spreadsheet:Importing DataOpen Excel, click the PowerPivot tab, Manage:
  24. 24. Upon clicking Manage, a new window should appear. From this window, you will import data. ClickFrom Database and select From SQL Server:Type in the Server Name, Authentication mode, and browse to the AdventureWorksDW2012 database:
  25. 25. Click Next, choose “Select from a list of tables and views to choose the data to import” and click Next.The next screen is where we will select our data to import. For this example, choose FactInternetSalesand click “Select Related Tables”. The Select Related Tables button enables you to automatically selectevery table that is related to the source table selected:After clicking Finish, the import will begin. Once the import finishes successfully you should be able toview all the tables separated into sheets:Creating PivotTableBefore creating a KPI we will need to slice and dice our data into a PivotTable. To do this, clickPivotTable on the ribbon bar and choose New Worksheet:
  26. 26. Our boss wants a PowerPivot report that displays quarterly profit percentages on AdventureWorks’ totalsales. Before we design the report we need to determine the calculation that we’ll need to get to thispoint. If I take the product cost and subtract it from the sales cost I’ll get my total profit in dollars.Then I’ll take that amount and divide it by the total product cost, which will give me the totalpercentage.OK, easy enough. Let’s design the dashboard.First, we need to slice the dashboard up into quarters since we only want to report on quarterlynumbers. To do this, drilldown the DimDate header and drag down CalendarYear and CalendarQuarterinto the Rows section: (Make sure CalendarYear is on top of CalendarQuarter)We now have a PivotTable with something on it. Next we need to add some values. Drilldown theFactInternetSales header and drag SalesAmount down to the Values section:
  27. 27. Our Pivot table is coming along. We now have the total sales amount broken down by each quarter.Next we’ll need to add the total product cost. Drag TotalProductCost to the Values section belowSalesAmount:Create Calculated FieldsSo far, so good. The next column we need to add will be a calculated column. We will need todetermine the profit from each quarter. To determine the profit we will need to subtract the sales
  28. 28. amount from the product cost.Under the PowerPivot tab, click Calculated Fields and select New Calculated Field:On the Calculated Field window select the table name, give the field a name, and enter your formula.For our example, we will use the FactInternetSales table, name it TotalProfit, and enter our formula as=SUM(FactInternetSales[SalesAmount])-SUM(FactInternetSales[TotalProductCost])We have now created a calculated field that will subtract the sales amount from the product cost. Afterclicking OK, the new column should appear to the right:
  29. 29. Now we need to create a calculated field that will give us the percentage of profit. To do this, we willneed the outcome of the above calculated field.Choose New Calculated Field and enter the following:Table name: FactInternetSalesCalculated field name: ProfitPercentageFormula: =[TotalProfit]/SUM(FactInternetSales[TotalProductCost])In this example we used the outcome of TotalProfit and divided it by the Total Product Cost. Afterclicking OK, the new column should appear to the right:
  30. 30. To format the calculated columns, highlight the column and right click and choose Format Cells:Create KPIThe dashboard is almost is complete except for the KPI. To add a KPI click KPI’s, New KPI:
  31. 31. On the KPI screen we will need to choose the calculated field that we are basing our KPI values on. Wewill also choose absolute value because we didn’t create another calculated value to compare with. Wewill change the Absolute Value to 1 and move the thresholds like below. The status thresholds arereporting on the percentage in decimal form, for example, 70% looks like .70.After clicking OK, we notice that the KPI’s have been added to the right:
  32. 32. Next StepsTo find out more about KPIs in PowerPivot click here to visit Microsofts Office site.Creating basic PowerPivot dashboards are fairly easy and usually dont require any IT resourcesexcept to provide a data model and possibly security access to the database for importing data.You can find other tips regarding Microsoft Excel Integration here.