Chapter 26. Advanced Reporting Services Charting

In the last chapter, we introduced the fundamentals of SQL Server Reporting Services. Reporting Services allow you to quickly create visually appealing charts or formatted reports for print or export to other formats. We also explored the ability to produce OData feeds and discussed the use cases for doing so.

In this chapter, we develop some more advanced skills by building on the basic reporting we did in Chapter 25. We will first develop a basic drill-down report that allows us to drill through the members of our chart. We will then move on to a more advanced technique using JavaScript to spawn a new window with the drill-down report.

The second technique, while more complicated, is worth noting because it enables you to drill down to anything that supports a URL. You could drill into another report as we’ll show here, or into any web application. It’s not a technique that’s been broadly used, but it is very useful.

The mechanics of what we’re doing are pretty simple. We have an existing report that we’re going to enhance with a click-through action. When you click on a product line in the report, you will pass that selected product line as a parameter to a second report.

The first thing you need to do is create that second report. It’s no different than your first report other than accepting a parameter for a product line by which you will filter your data. Let’s do it!

Start by selecting the All Documents view from the Library ribbon. Then choose to create a new Report Builder report, which will be our drill-down report. See Figure 26-1.

To limit the results of your query, apply a filter to your dataset that restricts the data to only data where the product line matches the parameter passed to our report.

  1. Within the Report Data pane on the left, expand the datasets node, right-click on your data set and launch the Dataset Properties dialog.

  2. Select the Filters tab, as shown in Figure 26-9.

  3. Add a new Filter.

  4. Choose ProductLine as the expression to filter.

  5. Choose Like as the operator.

  6. Launch the formula builder to define our constraint.

You may wonder why we’ve told you to select Like instead of Equals as your operator. When filtering data from a cube, it’s important to remember that your dimensions are all defined as hierarchies. Therefore, the table name is included as a part of the hierarchy. A good example of this is [Queues]\[Bikes], where you will be passing online bikes as your product line. For this reason, you’ll want to use a Like operator and apply wildcards in your filter.

Out of the box, SQL Server Reporting Services supports the ability to have basic drill-down reports. When you click on a hyperlink or an area of a chart, you can pass along a parameter and drill down to another report. The client’s browser will redirect to the new report, leaving the context of the top-level report.

While the simple drill-down has great functionality and is fairly easy to implement, sometimes you’ll want to keep the context of the original report and spawn a new window for the drill-down details. A second approach will use some JavaScript to spawn a dialog for a drill-down report and could be used to open any URL while maintaining the context of the original report.

Your original report should now display in the Report Builder editor. Right-click on the chart series and activate the Series Properties dialog, as shown in Figure 26-18.

In the Series Properties dialog, select the Action tab, as shown in Figure 26-19. Actions allow you to define what happens when a user clicks on a member of this series in the report at render time.

Now, run the report and try it out. You’ll notice that your mouse cursor now indicates a link when you hover over a chart element, even inside the Report Builder preview shown in Figure 26-20.

When you click on a chart element, you will drill down, automatically replacing the original report. Don’t forget to save your changes. All this will work the same way via SharePoint.

In this example, we’ll build on the previous drill-down, but will leverage JavaScript and the URL parameter support of Reporting Services Integrated Mode to keep your users in context by providing a drill-down report as a pop-up.

  1. Start in the All Document View of your PowerPivot library.

  2. Edit your main report by launching Report Builder from the Edit Control Block.

  3. Once again, right-click on the chart series to access the Series Properties.

  4. Select the Action tab again, as shown in Figure 26-22.

  5. Instead of selecting Go to report as the action, change it to Go to URL.

  6. Launch the formula builder to create a URL.

  7. Enter the expression in your code example and click OK. Don’t worry; we’ll discuss this expression in detail shortly.

  8. Save the report.

Note

The JavaScript in this example won’t execute in the Report Builder Preview. You need to save the report to SharePoint to see it work.

After saving the report, view the report from SharePoint. Simply click on a product line to launch the drill-down report in a pop-up.

Now that you’ve seen an example in action, let’s talk about the details of the expression that was constructed behind the scenes. It is as follows:

="javascript:void(window.open(
'http://sp2010/book/dave/_layouts/ReportServer/RSViewerPage.aspx?
rv:RelativeReportUrl=/book/dave/Reports/ProductLineDrillDown.rdl
&rp:ProductLine="+ Fields!ProductLine.Value + "
&rv:HeaderArea=None&rv:Toolbar=None
&rv:ParamMode=Collapsed','_new','toolbar=no, location=no,
directories=no, status=no, menubar=no, scrollbars=no, resizable=no, 
copyhistory=yes, width=600, height=350'))"

Let’s walk though each concept used in this expression. Web browsers can execute JavaScript in place of a hyperlink by using the javascript: someFunction() syntax:

javascript:alert('hello world')

To open a new window in JavaScript, you can use the window.open syntax:

window.open(someUrl, windowName, parameters)

Let’s build the URL to access the Reporting Services report dynamically and add on some special parameters that Reporting Services Integrated Mode accepts for URL access. Start with the URL to the Reporting Services viewer page that you are able to grab by browsing to your report inside SharePoint.

The ? begins the URL parameters that we are passing in.

Parameters beginning with rv: are Report Viewer parameters. For instance:

Parameters beginning with rp: are the parameters that the report itself is looking for. Set the ProductLine parameter using the value of the Productline field in our dataset by appending it to our expression:

"'http://sp2010/book/dave/_layouts/ReportServer/RSViewerPage.aspx?
rv:RelativeReportUrl=/book/dave/Reports/ProductLineDrillDown.rdl
&rp:ProductLine=" + Fields!ProductLine.Value + "
&rv:HeaderArea=None&rv:Toolbar=None&rv:ParamMode=Collapsed"

Now, let’s set a bunch of optional parameters to control the look and feel of the new window:

'toolbar=no, location=no, directories=no, status=no, menubar=no,
scrollbars=no, resizable=no, copyhistory=yes, width=600, height=350'

Finally, by wrapping the entire window.open function inside the void() function, you are able to tell the browser not to redirect to a new URL when someone clicks on the hyperlink.

If you are a beginner with Reporting Services, you may want to try these examples a few times to become comfortable with the techniques. In this chapter, you created and styled charts by leveraging the Report Builder designer. You created both simple drill-down capability, as well as leveraged JavaScript to keep your users in context and open up a URL in a pop-up window.

In the next chapter, we’ll discuss other uses of Reporting Services including leveraging subscriptions to deliver your reports on a schedule, and data alerts to inform your users to conditions in the data.