Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98522 Viewers
61 Video lessons · 85812 Viewers
71 Video lessons · 69715 Viewers
56 Video lessons · 102027 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.