[box type="note" align="" class="" width=""]This article is an excerpt from a book authored by Dinesh Priyankara and Robert C. Cain, titled SQL Server 2016 Reporting Services Cookbook.This book will help you create cross-browser and cross-platform reports using SQL Server 2016 Reporting Services.[/box]
In today’s tutorial, we explore steps to create reports on multiple axis charts with SQL Server 2016.
Often you will want to have multiple items plotted on a chart. In this article, we will plot two values over time, in this case, the Total Sales Amount (Excluding Tax) and the Total Tax Amount. As you might expect though, the tax amounts are going to be a small percentage of the sales amounts. By default, this would create a chart with a huge gap in the middle and a Y Axis that is quite large and difficult to pinpoint values on.
To prevent this, Reporting Services allows us to place a second Y Axis on our charts. With this article, we'll explore both adding a second line to our chart as well as having it plotted on a second Y-Axis.
First, we'll create a new Reporting Services project to contain it. Name this new project Chapter03.
Within the new project, create a Shared Data Source that will connect to the WideWorldImportersDW
database. Name the new data source after the database, WideWorldImportersDW
.
Next, we'll need data. Our data will come from the sales table, and we will want to sum our totals by year, so we can plot our years across the X-Axis. For the Y-Axis, we'll use the totals of two fields: TotalExcludingTax
and
TaxAmount
. Here is the query by which we will accomplish this:
SELECT YEAR([Invoice Date Key]) AS InvoiceYear
,SUM([Total Excluding Tax]) AS TotalExcludingTax
,SUM([Tax Amount]) AS TotalTaxAmount FROM [Fact].[Sale]
GROUP BY YEAR([Invoice Date Key])
03-01 Multi Axis Charts.rdl
and click on Add.WideWorldImportersDW
.WideWorldImportersDW
.SalesTotalsOverTime
.WideWorldImportersDW
in the Data source dropdown.You can now see a chart with a second axis. The monetary amounts are much easier to read. Further, the plotted lines have a similar rise and fall, indicating the taxes collected matched the sales totals in terms of trending.
SSRS is capable of plotting multiple lines on a chart. Here we've just placed two fields, but you can add as many as you need. But do realize that the more lines included, the harder the chart can become to read.
All that is needed is to put the additional fields into the Values area of the Chart Data window. When these values are of similar scale, for example, sales broken up by state, this works fine.
There are times though when the scale between plotted values is so great that it distorts the entire chart, leaving one value in a slender line at the top and another at the bottom, with a huge gap in the middle. To fix this, SSRS allows a second Y-Axis to be included. This will create a scale for the field (or fields) assigned to that axis in the Series Properties window.
To summarize, we learned how creating reports with multiple axis is much more simpler with SQL Server 2016 Reporting Services.
If you liked our post, check out the book SQL Server 2016 Reporting Services Cookbook to know more about different types of reportings and Power BI integrations.