Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding a sparkline to a drilldown matrix

From: SQL Server Reporting Services in Depth

Video: Adding a sparkline to a drilldown matrix

I'm beginning here in Report Builder once again with a blank report and a data source pointing to the regular AdventureWorks database. I am going to add a matrix to this report and add a sparkline into that matrix so that we will have multiple sparklines automatically generated for whatever rows are returned from the database. Now, most of our work in this example will be in preparing the dataset. I am going to take the same idea that I used in the previous example, of getting total sale broken down by year and month, but this time I'm going to start joining this together with the salesperson and region data so I can have a matrix that drills down to multiple levels of information.

Adding a sparkline to a drilldown matrix

I'm beginning here in Report Builder once again with a blank report and a data source pointing to the regular AdventureWorks database. I am going to add a matrix to this report and add a sparkline into that matrix so that we will have multiple sparklines automatically generated for whatever rows are returned from the database. Now, most of our work in this example will be in preparing the dataset. I am going to take the same idea that I used in the previous example, of getting total sale broken down by year and month, but this time I'm going to start joining this together with the salesperson and region data so I can have a matrix that drills down to multiple levels of information.

So I'll create a new dataset. I will call this SalesInfo. Jumping into the Query Designer, I will first go and get a very similar set of data to what we've got in the previous example, into the SalesOrderHeader and select OrderDate and TotalDue. But what I also want here is information about what salesperson was responsible for this order and what region does that salesperson handle. Well, that information isn't in this particular table. There is no name here. I do have a SalesPersonID. So let's start with that.

So I will select that as a third column. We will run that query just to take a look. Well, I am getting back 279, 282, 276, some kind of ID for a salesperson. Well, let's take a look and see if there's a simple salesperson table that I can join that to. There is a salesperson table, but it seems to be joining somewhere else. We've got BusinessEntityID and TerritoryID, but there's no names involved here. There is no actual name of a territory nor of the salesperson. That's because in AdventureWorks there is actually quite a lot of different tables that need to be joined together to get that data.

However, there is a view in AdventureWorks called vSalesPerson that's already joining some of that information together. VSalesPerson contains first name, last name. It also contains the territory name and the region name that this salesperson is responsible for. So this is the table that I actually wants to join with that SalesPersonID. But here's the problem: there is no obvious join column here. I've got BusinessEntityID, but not a SalesPersonID. Well, I might try and experiment.

First, if I just select, say, the last name of the salesperson and try and run this query, is it going to work? Well, now I get this error message. Well, these tables aren't related. We have the Auto Detect option on, but it can't figure out how to tie these two things together. I am going to have to do that myself. So I am going to turn Auto Detect off. What that will do is enable this option here called Add Relationship, and I can manually say how those tables are connected to each other. And it actually is from SalesPersonID in the SalesOrderHeader to BusinessEntityID in vSalesPerson.

Now again here, I'm not really trying to talk about the AdventureWorks example here. Take this as an illustration of how you would connect two tables if they weren't explicitly defined in the database as having those connections. So I am going to click that button. When I do that it seemed to do something. I have this Edit Fields option came up, but I can't see anything. It's not obvious. That's because the Relationship section is often hidden in your Query Designer. If you want to see it, click the little dropdown arrow and you can actually have this window section appear with the Left Table, Join Type, Right Table.

And this is what I need to do is describe this relationship. Because I'd clicked that once, I already have an entry in the Relationship section. So I can double-click in here. First I select the Left Table. It already understands that in my current query I am describing two tables or two views or one of each as we have here: SalesOrderHeader and vSalesPerson. SalesOrderHeader is the table that I want here. I want the right table to vSalesPerson. It is an inner join. And then I double- click here to describe what the actual fields are that join these two together.

It doesn't actually matter which one was on the right or the left, because we are doing an inner join here. But the left table was SalesOrderHeader and that had SalesPersonID, and the right one was BusinessEntityID. Click OK. Now, if I go ahead and run this query, what we are getting is the OrderDate and order amount and the LastName of the related salesperson. Because of the indexing structure of the database, we are getting them back in a rough kind of order of salesperson here, but it looks like they're being joined the way that we would want them.

But I need a little bit more than this. So back into the vSalesPerson table, I want LastName, and I'm also going to go for the territory name. Run that again. I will find that some territories don't actually have a name, or some salespeople aren't associated with one, but most of them are. In fact, I no longer need SalesPersonID anymore, because I actually have the last name, which is what I'm really interested in. So I will select SalesPersonID and just get rid of that. Ok, what next? Well, I want to start grouping together the TotalDue amount, so adding that together for each salesperson, but grouped by month and year again.

I can start off by selecting to sum the TotalDue amount and it will automatically start to group the others. I am just going to order these in here, just to make my thinking about them a little easier. We are trying to sum the TotalDue amount. We are grouping by OrderDate, and then I will go TerritoryName and finally, LastName. I don't strictly need to do that here, but it makes it easier now that I have to jump into the Edit as Text section to make my final grouping choices to this. So very similar to the last time, what I'm going to do is select the OrderYear and OrderMonth values, construct those as columns by extracting them out of OrderDate.

I am going to allow the inner join to happen the way it was described in Query Designer and then finally, in GROUP BY, I want to start grouping them first by year, then by month, then by territory, and then by LastName. Taking care just to scan that all the commas are in the right place so I don't either have too many or too few, this looks correct. I am going to go ahead and test this. And this looks about right. We are getting different amounts being totaled up for any particular year and month for a territory for a salesperson's last name.

Again, your focus here should be on what can you do with this kind of data, what can you do with this kind result? We are going to take it into a matrix. So click OK and click OK. Over to the Insert tab, I am going to come to the Matrix section and add a Matrix Wizard. I will choose that dataset I just defined. Click Next. Now, I could actually define this matrix a couple of different ways. I could have the months and years running across the top, or I could have them down the left-hand side and the regions across the top. What I'm going to do is drag on TerritoryName into Row groups and then also LastName.

So we are going to be starting to group these things together first by their territories-- so the Australia, United Kingdom, United States--and then within each territory we will be grouping by LastName. Well, that would just give us a table. To turn this into a matrix we also need column groups, and that is going to be grouped first by year and then within that by months inside that year. Well, finally, the most important thing, we need an actual value, which is the Sum_TotalDue. This should be enough to get our matrix configured. I am going to click Next and select, yes, the Blocked, subtotal above will do.

Stepped might work as well. In fact, I'm going to select Stepped. It's a little smaller on the page. The functionality of these is exactly the same. It's just a slightly different visual appearance. Then next into the style, and I'll go with Corporate. Click Finish. It's going to drag this into the page and go ahead and run. Now we have a matrix with multiple levels of drilldown ability into it. Reviewing our regions down the left- hand side, that actually includes the blank region where the word no regions specified for that particular salesperson.

The year's along the top, and we can drill down into a particular year and view every month or we can drill down into a region and view the individual salespeople for that region. Now, there is a bit of complexity going on here, that the totals are a little bit too much here, so I am going to jump back into Design view. And I want to format all these sums, all the various totals that it's calculating for us. I want them all as currency. I could do them all individually, but here is an easier way. I click one of them to make sure that I'm selecting the text box.

I don't want to select the individual text. So click once and get the text box in the lower right-hand corner and then Shift+Click in the upper left-hand corner. Again, all I am selecting here are wherever we are summing totals together. So it should be, for my case, just these nine rows. Come up to the number section on the Ribbon. Change that to Currency. We also don't need anything after the decimal point. I don't really mind what cents were sold in a particular month. So I am going to hit the button to decrease decimal. I will hit that twice. In fact, I want to get rid of everything after the decimal point.

So I am clicking it until it turns gray and there is no more options there. Let's run it again. That looks a little better. We are at least successfully formatting these with the Currency format. So now what? Well, a lot of this was meant to be about adding a sparkline to this. So back into Design view. What I want to do is add a sparkline just right in here, before the total amount. Here is the best way to do it. I am going to click anywhere in the matrix to select it and then select the column under Total. Now, bear in mind you have multiple ones here.

I'm looking at the total for all the regions, so the last column. I am going to right-click the top gray bar, the gray handle that I have here, and choose to insert column to the left. And I am going to be inserting my sparklines here. Now, the question is where, because there is a big difference between putting a sparkline in on this cell as opposed to this one or this one or this one. What I want is a sparkline that's associated with each individual salesperson. And that means I need to be conscious of what row the salesperson name turns up on, which is this one, where we have last name being spat out.

If I had added the sparkline on this cell, it would be a sparkline for the entire territory. Reporting Services and Report Builder is very sensitive to where you put your sparklines in a matrix, because it's going to try and target the right data for that sparkline. So I want it in here. And here's how we do it. Up to the Insert section, select Sparkline, and then just click in that area. So clicking in that cell gives me the sparkline type. I'm going to do actually a column sparkline here and click OK. We are seeing a little bit of dummy data in here.

Now, it's not going to understand what data it should be showing, but that's easy to add. I select the sparkline itself, so clicking in it or right-clicking in it until I get the chart data window. And I'm going to drag across the Sum_TotalDue. Again, be very helpful where you're dragging, because if you drag across another element, like the matrix, it's easy to mess things up. So drag that into Values, and then in Groups I want to split this up by year and month again. So over into Groups, first is OrderYear and then is OrderMonth.

I don't need to worry about Territory and LastName, because I'm already putting in the correct row that's already been split up by Territory and LastName. So Reporting Services should be smart enough to understand the correct data and correct numbers to show. So let's try this. Go ahead and run. I don't see anything right now, because that cell, that particular sparkline, should only appear when I can see the individual last names. So I'll open up Canada, and yup, I'm getting the sparklines appear. These are column sparklines. I open up France, I see that one.

I open up the Northwest, I see several sparklines. Now, one of the problems that I'm having here is the sparklines aren't necessarily matching up against each other. Say, for example, if I look at the settings for France, there were no sales at all in 2005, but I'm still seeing some entries in here, some columns showing up. And that's because the sparklines by default are going to fill themselves to the width of the available data. What I might want to have happen is that they be a bit more representative, a bit more compared to each other.

Meaning that instead of each sparkline filling as wide as it can, I'd like it to pay attention to what the other sparklines are during in this matrix. Here's how I'd do that. Back into Design view. I am going select that sparkline again and then right-click it. What I'm hoping for are Sparkline properties here. And we have two options here, for the Vertical Axis Properties on the Horizontal Axis Properties. Horizontal is what I am first interested in. I will select that. And it's first asking is this category or scalar, meaning is it going by numbers or dates? You might think we need to go by numbers and dates, but we don't really need to do that because we're already putting things together absolutely fine by our explicit years and months.

What I need instead is this, option to align the axes, not just inside the territory, but in the larger matrix, or Tablix region, and click OK. I don't see any visual change here, but if I run this again and start expanding some of these, what I will actually see is a different kind of layout now representing different amounts of data for the people who have been doing this all along and the people who have only been doing it for a shorter time. Similarly, what we have actually got happening is that the horizontal axis here might be mismatching.

What I mean by that is we may have people that are doing immense amounts of sales, like Mitchell in the Southwest, but Mitchell's columns are just as high as, for example, this entry up here in Australia whose numerical values are actually much less. So now we are actually matching across the horizontal. We also need to compare these across the vertical. It's done in a very similar fashion. You don't have to do this. You might find your sparkline useful enough, but if you want them to be scannable and comparable with the other, then we jump back in, I go to the Vertical Axis Properties, and also align these axes within the matrix.

Click OK and run this. Now what we should see is it taking something was actually lower amount of sales, like the Australian region, and comparing that to the Southwest region with higher sales, we should be able to relate them to each other and find them easier to just visually scan and realize who is actually doing more numbers than another person. From this point, we are likely to want to experiment with the width of the columns that the sparkline is in, and also with the formatting. You'll find that with the sparklines selected, you do have things like the color palette that you can experiment with. Very similar to working with a normal chart.

But once you've fueled up with the correct data, well, you can experiment with these all you want.

Show transcript

This video is part of

Image for SQL Server Reporting Services in Depth
SQL Server Reporting Services in Depth

40 video lessons · 9838 viewers

Simon Allardice
Author

 
Expand all | Collapse all
  1. 12m 6s
    1. Welcome
      1m 9s
    2. What you need to know
      1m 36s
    3. Exploring SQL Server Reporting Services components
      4m 17s
    4. Reviewing SQL Server versions
      5m 4s
  2. 49m 41s
    1. The elements of a report
      3m 10s
    2. Creating a report with Report Builder
      12m 11s
    3. Grouping table regions on a report
      6m 1s
    4. Joining data from multiple tables
      4m 33s
    5. Formatting report elements
      4m 34s
    6. Using functions in a report
      11m 0s
    7. Displaying data in a matrix
      8m 12s
  3. 24m 9s
    1. Filtering data and adding parameters to a report
      5m 35s
    2. Customizing report parameters
      5m 4s
    3. Sorting data in a data region
      4m 7s
    4. Applying interactive sorting
      4m 57s
    5. Creating a drillthrough action to connect reports
      4m 26s
  4. 49m 57s
    1. Introduction to charting in Reporting Services
      4m 16s
    2. Creating a column chart
      8m 35s
    3. Adding a generated average to a chart
      4m 5s
    4. Creating a pie chart
      8m 19s
    5. Using sparklines
      6m 38s
    6. Adding a sparkline to a drilldown matrix
      14m 34s
    7. Adding data bars
      3m 30s
  5. 21m 48s
    1. Adding indicators to a report
      7m 52s
    2. Using and configuring gauges
      5m 30s
    3. Using maps in Reporting Services
      8m 26s
  6. 38m 14s
    1. Creating modular reports with report parts
      4m 36s
    2. Adding and updating report parts
      4m 37s
    3. Using subreports and nested regions
      4m 28s
    4. Configuring headers and footers
      3m 9s
    5. Printing and exporting reports
      3m 45s
    6. Using page breaks
      5m 37s
    7. Creating and using shared data sources
      8m 11s
    8. Creating and using shared data sets
      3m 51s
  7. 27m 20s
    1. Organizing reports in Report Manager
      3m 1s
    2. Adding users and configuring report security
      5m 24s
    3. Configuring subscriptions
      5m 13s
    4. Creating a linked report
      4m 8s
    5. Using Report Designer in SQL Server Data Tools
      9m 34s
  8. 1m 2s
    1. Goodbye
      1m 2s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed SQL Server Reporting Services in Depth.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.