SQL Server Reporting Services (SSRS) For Application Developers Kevin S. Goff www.KevinSGoff.net Microsoft SQL Server MVP
Kevin S. Goff – Brief BIO Developer/architect since 1987 / Microsoft SQL Server MVP Columnist for CoDe Magazine since 2004, “The Baker’s Dozen” Productivity Series”, 13 tips on a SQL/BI topic Wrote a book, collaborated on a 2nd book Frequent speaker for SQL Server community events and SQL Live!360 Conferences Email: kgoff@kevinsgoff.net My site/blog: www.KevinSGoff.Net (includes SQL/BI webcasts) Releasing some SQL/BI video courseware in the future
Some SSRS articles I’ve written in CODE Magazine http://www.codemag.com/article/1705061 http://www.codemag.com/article/1605111 http://www.codemag.com/article/1108101
Attendees pick topics SSRS Drilldown capabilities Running Totals Matrix capabilities SSRS Data Driven Subscriptions Putting an SSRS report on an ASP.NET webpage Launching an SSRS report and exporting to PDF from inside an SSIS package Interactive sorting Building Charts with dual-Y axis definitions Generating Performance Gauge and sparkline data visualizations Implementing multi-valued parameter selections with a stored procedure Subreports Launching child report from parent report as a Report Action Nested page groupings/pagination Hiding columns based on user input or based on user security/authentication Reporting against OLAP cubes Building charts with multiple data series Cross highlighting/filtering Charts multiple report objects that stretch vertically Conditionally suppressing repetitive report subtotals LookupSet and custom VB code Launching an SSRS report from .NET with multiselect parameter values Launching a child SSRS report in a separate browser window/tab Conditional aggregations Implementing Running Aggregations in a report Implementing a tab-style interface for navigation to report page/sections Cascading parameters Some tips on Analytic Charts Annotating parameters correctly Multiline tooltips Determining which users have run reports
1 - SSRS Drilldown capabilities Initially everything collapsed, based on initial parameter settings Initially everything collapsed, based on initial parameter settings User can expand Grand Total label to show ship methods, and expand ship methods to see Vendors
1 - SSRS Drilldown capabilities To implement drilldown, there’s no actual drilldown feature Instead, it’s a matter of hiding a group level, and toggling the visibility based on a parent label For the Group, go to Visibility, and set the Toggle Item to a label at the parent level To initially suppress the group level, set Visibility “when report is initially run” to false. Or it can be based on report user parameter References textbox
1 - SSRS Drilldown capabilities And then to implement at further child levels, same concept Set toggle item to the label used for the parent group
2 – Running Totals (Running Aggregations) To implement running aggregation values, using the function RunningValue First Parameter is the column value being aggregated Second parameter is the aggregation (sum, Avg, Max, etc.) Third parameter is the scope of the aggregation (the group)
3 – Matrix capabilities Matrix example Years across the top, even though we don’t know how many years there could be The column group could be markets, or products, or quarters, etc. Matrix option for % of Total Years spread across in reverse order % of total based on sales with respect to totals across all years for the single shipper, or totals across all shippers for the year
3 – Matrix capabilities Matrix example Years across the top, even though we don’t know how many years there could be The column group could be markets, or products, or quarters, etc. We can insert columns inside the matrix to show more data or calculations The two calculation expressions (for % of row or column total) are expressions within the row/column group The SUM aggregation will occur for the scope of shipper/orderyear Result set columns for Shipper and OrderYear defined as Row and Column Groups
3 – Matrix capabilities The % of Total Calculations can refer to textboxes that are part of a spreading element column group
4 – Data Driven Subscriptions Requirement: must use SQL Server Agent! One report, many recipients for different parameters, on a schedule One report, many output destinations for different parameters, on a schedule We can populate a relational control table in SQL Server with information to drive the report subscription SSRS web interface will prompt us for necessary fields The source of data for the report (as well as the data source for the relational control table that contains the subscription information) must have credentials securely on the server (for unattended execution) This can be a time saver – if you have a large # of recipients Also dynamic – will pick up changes when we insert new rows to the relational control table Link on my website to more details: http://www.commongroundsolutions.net/SSRS_DataDrivenSubscriptions_Methodology.pptx Generated output name Can be UNC location, or SharePoint Document Library, or email address MHTML, Excel, PDF, TIFF, CSV, etc Relational source: Key parameters OLAP source: dimension key
4 – Data Driven Subscriptions Must provide source for the table holding subscription information Credentials must be stored securely
4 – Data Driven Subscriptions Interface will detect the parameters required by the report when it’s run unattended We can use our mapping table (note the first parameter was generally called “Param1”)
4 – Data Driven Subscriptions Next, provide the delivery method Then provide SSRS with all the columns from our mapping table, that correspond to the subscription requirements
4 – Data Driven Subscriptions Finally, provide a delivery event (preferably a shared schedule)
5 – SSRS Report on ASP.NET webpage Drop instance of SSRS Report Viewer on an ASP.NET webpage Also needs Script Manager We’ll need code in the code-behind to set report properties
5 – SSRS Report on ASP.NET webpage Note: suppose this parameter was a multi-select and you want to pass multiple values. Must pass string array: public string[] aYears; aYears = ListOfYears.ToArray(); Another example – where we pass in our own parameter(s)
5 – SSRS Report on ASP.NET webpage One more note! If you want to pop up the report in another browser or tab… "javascript:void(window.open('" + ReportServer + "rptName&Param1=" + Param1Value + _ "&Param2" + Param2Value + "','_blank'))"
6-Launching SSRS report inside an SSIS package C# code inside SSIS Script to run a report unattended .NET references required
7-Interactive sorting Runtime ability for user to sort on any column in the browser Design-time property in column header textbox, for Interactive Sorting
8-Charts with dual-Y axis definitions Chart plots two numeric columns on two different scales Helpful for plotting percentages on a different axis/scale Primary Y-Axis (sales in millions) Secondary Y-Axis, for percentages (since they need a different scale)
8-Charts with dual-Y axis definitions For the second measure, you can right-click to go to Properties for the data series, then go to the Axes and Chart Area Properties and set the vertical axis to secondary To render the percentages as a line instead of a bar chart, right-click and change the chart type
9-Performance Gauge/sparkline visualizations Video to create from scratch: http://www.commongroundsolutions.net/SSRSPerformanceGauge1_of_4.zip http://www.commongroundsolutions.net/SSRSPerformanceGauge2_of_4.zip http://www.commongroundsolutions.net/SSRSPerformanceGauge3_of_4.zip http://www.commongroundsolutions.net/SSRSPerformanceGauge4_of_4.zip
10-Multi-valued parameters with stored procedure Reporting Services passes a multi-valued parameter as a comma-separated string to a stored procedure Must create a table-valued function in the database, to convert a CSV string to a table variable Stored Procedure can receive the CSV string, call the TVF, and join the results to other tables
11-Subreports A single report can only render one instance of a one-many relationship. If there are multiple one-many relationships for multiple levels of detail, we need to implement subreports Basically, we create a main report where the primary dataset contains a key (in this instance, a product key) that can be passed to two child reports as parameters The 2 child reports are built with the expectation they’ll receive a product key parameter Then in the main report, add them as subreports Multiple levels of detail Main report shows each product, and then within each product, sales from both internet sales and reseller sales
11-Subreports In the main report, add references to the two child reports as subreports In the subreport properties, reference the child report, and pass the Product Key from the main dataset as a parameter to the child subreport
12-Launch child report from parent report User clicks on state (Oregon), and report launches a 2nd report (which shows sales for cities in Oregon) Can use Report Action feature in data point of main report to launch a second report, with parameters that the child report expects
12-Launch child report from parent report The connection point might be a textbox, or a data series point on a chart, or the Polygon properties of a map Find the Action Page, specify “Go to Report”, and define the child report. The interface will expose the parameters that the child report expects, and we can pass values from the main report
13-Nested page groupings/pagination Not only can SSRS show “Page X of Y”, it can also show pagination for groups within the report Just need to define some properties for the group
13-Nested page groupings/pagination For the group (in the properties sheet), need to define the Page Break properties Pagination won’t work correctly at the Group level unless we set these.
14-Hiding columns Column visibility Use SSRS global variable User!UserID to call a stored procedure to query a custom control table that holds rights definitions for specific columns SSRS does not have any built-in security feature to define whether users can see (or not see certain columns. But we can implement a custom solution using control tables based on User ID, and the SSRS column visibility feature
15- Reporting against OLAP cubes SSRS Allows reporting against OLAP Cubes Good news: you can use the visual designer to drag/drop fact table measures and dimension attributes Not so good news: sometimes/often you need to modify the generated MDX code, or even write your own MDX code Column visibility
16 – Chart with Multiple Series These 2 bars represent 2 different series for the same month: Inventory and Shipments
16 – Chart with Multiple Series An average (maybe average daily inventory for the month) rendered as a line chart Series type that breaks out Inventory by multiple definitions (Cyan, Yellow, Red, Blue, Grey) Series type that breaks out Shipped by multiple definitions (Green and Yellow) Result set that drives chart Within each month, a category group definition for (I)nventory and (S)hipped (XAxisType)
17 – Cross-highlighting charts Visual Studio Live! Orlando 2013 17 – Cross-highlighting charts User wants to click on U.K. for 2013 and highlight all relevant parts of that chart and other charts © 2013 Visual Studio Live! All rights reserved.
17 – Cross-highlighting charts Visual Studio Live! Orlando 2013 17 – Cross-highlighting charts All relevant areas for UK 2013 now in Yellow © 2013 Visual Studio Live! All rights reserved.
17 – Cross-highlighting charts Visual Studio Live! Orlando 2013 17 – Cross-highlighting charts First, create a hidden parameter called HotSelect Third, for each chart, go to series properties and Fill. Set Color Expression Second, for each chart, go to Series properties and Actions. Set action as the same report (to “relaunch”) and pass in HotSelect Parameter based on current Year and Country © 2013 Visual Studio Live! All rights reserved.
Right-click on the row selector for the subtotal row, select “Row Visibility” and then hide the row using the COUNTDISTINCT function