Reporting in SQL Server Customize the visual appearance of your reports

Reporting in SQL Server Customize the visual appearance of your reports

Reporting in SQL Server - Customize the visual appearance of your reports

SQLShack

SQL Server training Español

Reporting in SQL Server – Customize the visual appearance of your reports

October 3, 2016 by Steve Simon

Introduction

As we are nearing the end of the North American summer, I thought that we would take a lighter look at nifty ways of reporting information. In today’s “fireside chat” we have a look at a unique way of displaying our information using charts and line graphs all in one single chart (see below). We shall take things one step further and work with the color fill of the vertical bars to reflect the values that they represent.

Let us begin

We are going to look at some sales data from one of my South African clients. Obviously, the numbers have been altered for confidentiality reasons. The client had requested a series of reports in bar chart format showing actual revenue while having the monthly goals display in line graph format. Moreover, the vertical bar color fill would reflect the ratio of the “actual” to the “goal”. Red being definitely under target, yellow as near target and green above target. Our finished chart may be seen below: Let’s see how we can produce this chart. We begin by open “SQL Server Management Studio” and opening the SQLShack database (which we have worked with in past “get togethers”). We look at the “MonthlyGoalvsActual” table which contains sales and goal data for the financial year 2015. We note that there are three columns. The first, the year and month measured, the second being “monthly goals” and the third actual month’s sales. In addition to these three fields, we also require the three character month name, which is obtained by through passing the year and month combination to a function (dbo.Monthee) which I created. Our code for this function may be found in Addenda 1. We begin by creating a stored procedure to pull this data (above).

Developing a report

Using SQL Server Data Tools 2010 or a higher version, we create a new “Reporting Services” project. Should you not feel at ease designing such a project, then do have a glance at my SQL Shack article entitled “Now you see it, now you don’t”, where I describe the process in great detail. /now-see-now-dont/ At this point, we shall assume that you feel comfortable working with a Reporting Services project. Opening SQL Server Data Tools, we create a new Reporting Services Project (above). We give our project a name (above). We accept and return to the report design surface. We must now add a new ‘Shared Data Source’(above). As I have mentioned many times before, a data source is similar to a garden hose. This garden hose connects to the tap on the house (the database) and the other end of the data source empties into a watering can (the dataset). We enter the name of the server and connect our new ‘Shared Data Source’ to the “SQLShack” database (above). We click ‘OK’ and ‘OK’ again to leave the “Shared Data Sources” dialogue box and we are returned to our report. Our next task is to develop a report. We now right click upon the “Reports” tab (above) and select ‘Add’ and then ‘New Item’ (as above). We create a new report called “SalesVSGoals”. We accept and return to the report. Our next task is to add a dataset. We right-click upon the ‘Datasets’ tab and select “Add Dataset” (above). The ‘Dataset Properties” dialogue box opens. We give our dataset the name “ActualVSGoalsDS”. We now click the ’New” button to create a new local ‘Data source’ (above). The local ‘Data Source Properties’ box appears. We give our local “Data Source” a name and point it to our ‘Shared Data Source’ that we created a few moments ago (above). After having created our local “Data Source”, we find ourselves back on the “Dataset Properties” screen. We select “Stored Procedure” as the “Query type” and select the “SalesGoal” stored procedure that we just created above (screen above). We choose ’OK’ to leave the “Dataset Properties” dialog box. We return to our report and we also find that the system has created the dataset (screen above). We drag a “Chart” from our “Toolbox” onto our report (above). The “Select Chart Type” dialogue box opens. We select a “Column” chart (above). Our “Column” chart is placed upon our report surface (above). Clicking on the chart and opening the “Properties Window”, we are able to link the dataset which we just created to the “DataSetName” property of the chart (see below). Having set the “DataSetName” (above), we click on the chart surface to bring up the “Chart Data” dialog box (see below). We select our “Goal” and “Actual” fields for the ∑ values (above) and set the “Category Groups” to “YearMth” and “Monthee”. Whilst we shall not be utilizing the “YearMth” combination per se, it will, however, be utilized to ensure that the months are correctly sorted according to chronology and not via the actual month name as alphabetical sorting would place the months in the wrong order (above). As “YearMth” is our primary sort field and as we do not want it to be visible on our final report, we right click upon “YearMth” and select the ‘Category Group Properties’ to open the “Category Group Properties” dialog box (see below). We click on the button as may be seen above. The “Label” function dialog box opens (see below). We alter the expression “=Fields!YearMth.Value” to We accept and the dialogue box closes, returning us to our report. We give our chart the title “Actual vs Goals” and set the name of the “X” axis to “Month” and the “Y” axis to “Dollars” (above). Running our report we find that our “Goals” and “Actuals” are shown. One issue is that only every second “Month” name is displayed. We wish to change this so that every month name appears on the “X” axis. By right-clicking upon the “X” axis, we select the ‘Horizontal Axis Properties’ option. The ‘Horizontal Axis Properties’ dialog box opens. We alter the “Interval” property from ’Auto” to 1 (above) and accept the change and leave the dialogue box. Having a look at our modified report, we see that every month is now displayed.

Altering the GOAL portion of the chart to be a line graph

As a part of the original specifications, the portrayal of monthly goals was to be a line chart. Now, most Excel folks would tell you that this is a “snap” to do! In Reporting Services creating the line graph (whilst simple) requires knowing where the change must be made. Within the “Chart Data” dialogue box, we right click upon the “Goal” field and select “Change Chart Type” (above). Once again the “Select Chart Type” dialog box opens. This time, however, we shall select “Line” (above). We accept the change. We are returned to our report surface. We note that the “Goal” vertical bars are no longer there but rather a line graph in its place (above). Running our report, we note the following. Let us now add the data values to the bar chart. We right-click upon one of the “Orange” bars (above) and select “Show Data Labels”. Sample label values appear in design view (above). These must be formatted to appear as Dollars. Right-clicking on one of the labels, we select “Series Label Properties” (above). The “Series Label Properties” dialogue box opens. We configure the display to “Number”, “Currency” and set the “Decimal places” to 0. We also set the format for any “Negative numbers” (above). Our chart looks as follows in design view (see below). Running our report we note the following (see below) Our last task is to compare the ratio of the “actuals” to the “goals” The business rules are as follows. If Actual to Goal is less than .7999 make the fill of the vertical bar “Red”. If Actual to Goal is between .800 and .9999 then the fill is to be “Yellow” If Actual to Goal is greater than .9999 then the fill is “Green” The code to achieve this is shown below: 123456 =Switch (isnothing(Fields!actual.Value) , "LightGrey", Fields!actual.Value /Fields!Goal.Value <= .799, "Red" , Fields!actual.Value /Fields!Goal.Value >=.80 and Fields!Actual.Value /Fields!Goal.Value <=.999, "Yellow", Fields!Actual.value /Fields!Goal.value >=1, "Green")

Changing the Fill colour of the Bar chart

We right-click upon any one of the orange bars and select “Series Properties” (above). The “Series Properties” dialog box opens. We select the “Fill” option and click the x button (above). We place our “Colour Code” into the “expression box” and click “OK” and “OK” to accept. We return to our report (see below). Clicking on the “Preview” tab, we find that color fill of our vertical bar “now represents the “actual to goal ratio” and that the line graph connecting the monthly goals is also present (above). Thus our chart and report are now complete.

Conclusions

When it comes to “charting”, our first thoughts are to “throw” all the data into a spreadsheet and work with it from there. The issue becomes what to do when dealing with large amounts of data and complex joining of data sources. SQL Server Reporting Services provides virtually the same functionality as an Excel spreadsheet, however, it has the underlying power to process large amounts of data in an efficient and effective manner. So we finish another “fireside chat”. I trust that I have left you with a few interesting ideas. As in past, if you do have questions, please do feel free to contact me. In the interim, happy programming!

Addenda 1

12345678910111213141516171819202122232425262728293031323334353637383940 USE [SQLShack]GO /****** Object: UserDefinedFunction [dbo].[Monthee] Script Date: 8/15/2016 3:06:09 PM ******/SET ANSI_NULLS ONGO SET QUOTED_IDENTIFIER ONGO create function [dbo].[Monthee](@YearMth as varchar(6)) RETURNS Varchar(6) AS BEGIN declare @Return varchar(6) BeginSet @return = case when right(@YearMth,2) = '01' then 'Jan' when right(@YearMth,2) = '02' then 'Feb' when right(@YearMth,2) = '03' then 'Mar' when right(@YearMth,2) = '04' then 'Apr' when right(@YearMth,2) = '05' then 'May' when right(@YearMth,2) = '06' then 'Jun' when right(@YearMth,2) = '07' then 'Jul' when right(@YearMth,2) = '08' then 'Aug' when right(@YearMth,2) = '09' then 'Sep' when right(@YearMth,2) = '10' then 'Oct' when right(@YearMth,2) = '11' then 'Nov' when right(@YearMth,2) = '12' then 'Dec' else 'XXX' end end RETURN(@return)endGO

References

Expression Examples (Report Builder and SSRS) Background Color Formatting by expression in SSRS Report Charts (Report Builder and SSRS) Author Recent Posts Steve SimonSteve Simon is a SQL Server MVP and a senior BI Development Engineer with Atrion Networking. He has been involved with database design and analysis for over 29 years.

Steve has presented papers at 8 PASS Summits and one at PASS Europe 2009 and 2010. He has recently presented a Master Data Services presentation at the PASS Amsterdam Rally.

Steve has presented 5 papers at the Information Builders' Summits. He is a PASS regional mentor.

View all posts by Steve Simon Latest posts by Steve Simon (see all) Reporting in SQL Server – Using calculated Expressions within reports - December 19, 2016 How to use Expressions within SQL Server Reporting Services to create efficient reports - December 9, 2016 How to use SQL Server Data Quality Services to ensure the correct aggregation of data - November 9, 2016

Related posts

Reporting in SQL Server – create a chart based on the data extracted for a given date range Create reports like a champion! Tips and tricks with Reporting Services Reporting in SQL Server – create a matrix based sub-report called by the previously created main report SQL Server and BI – Creating a query for the revenue projection Monitoring SQL Server Reporting Services 9,641 Views

Follow us

Popular

SQL Convert Date functions and formats SQL Variables: Basics and usage SQL PARTITION BY Clause overview Different ways to SQL delete duplicate rows from a SQL Table How to UPDATE from a SELECT statement in SQL Server SQL Server functions for converting a String to a Date SELECT INTO TEMP TABLE statement in SQL Server SQL WHILE loop with simple examples How to backup and restore MySQL databases using the mysqldump command CASE statement in SQL Overview of SQL RANK functions Understanding the SQL MERGE statement INSERT INTO SELECT statement overview and examples SQL multiple joins for beginners with examples Understanding the SQL Decimal data type DELETE CASCADE and UPDATE CASCADE in SQL Server foreign key SQL Not Equal Operator introduction and examples SQL CROSS JOIN with examples The Table Variable in SQL Server SQL Server table hints – WITH (NOLOCK) best practices

Trending

SQL Server Transaction Log Backup, Truncate and Shrink Operations Six different methods to copy tables between databases in SQL Server How to implement error handling in SQL Server Working with the SQL Server command line (sqlcmd) Methods to avoid the SQL divide by zero error Query optimization techniques in SQL Server: tips and tricks How to create and configure a linked server in SQL Server Management Studio SQL replace: How to replace ASCII special characters in SQL Server How to identify slow running queries in SQL Server SQL varchar data type deep dive How to implement array-like functionality in SQL Server All about locking in SQL Server SQL Server stored procedures for beginners Database table partitioning in SQL Server How to drop temp tables in SQL Server How to determine free space and file size for SQL Server databases Using PowerShell to split a string into an array KILL SPID command in SQL Server How to install SQL Server Express edition SQL Union overview, usage and examples

Solutions

Read a SQL Server transaction logSQL Server database auditing techniquesHow to recover SQL Server data from accidental UPDATE and DELETE operationsHow to quickly search for SQL database data and objectsSynchronize SQL Server databases in different remote sourcesRecover SQL data from a dropped table without backupsHow to restore specific table(s) from a SQL Server database backupRecover deleted SQL data from transaction logsHow to recover SQL Server data from accidental updates without backupsAutomatically compare and synchronize SQL Server dataOpen LDF file and view LDF file contentQuickly convert SQL code to language-specific client codeHow to recover a single table from a SQL Server database backupRecover data lost due to a TRUNCATE operation without backupsHow to recover SQL Server data from accidental DELETE, TRUNCATE and DROP operationsReverting your SQL Server database back to a specific point in timeHow to create SSIS package documentationMigrate a SQL Server database to a newer version of SQL ServerHow to restore a SQL Server database backup to an older version of SQL Server

Categories and tips

►Auditing and compliance (50) Auditing (40) Data classification (1) Data masking (9) Azure (295) Azure Data Studio (46) Backup and restore (108) ▼Business Intelligence (482) Analysis Services (SSAS) (47) Biml (10) Data Mining (14) Data Quality Services (4) Data Tools (SSDT) (13) Data Warehouse (16) Excel (20) General (39) Integration Services (SSIS) (125) Master Data Services (6) OLAP cube (15) PowerBI (95) Reporting Services (SSRS) (67) Data science (21) ►Database design (233) Clustering (16) Common Table Expressions (CTE) (11) Concurrency (1) Constraints (8) Data types (11) FILESTREAM (22) General database design (104) Partitioning (13) Relationships and dependencies (12) Temporal tables (12) Views (16) ►Database development (418) Comparison (4) Continuous delivery (CD) (5) Continuous integration (CI) (11) Development (146) Functions (106) Hyper-V (1) Search (10) Source Control (15) SQL unit testing (23) Stored procedures (34) String Concatenation (2) Synonyms (1) Team Explorer (2) Testing (35) Visual Studio (14) DBAtools (35) DevOps (23) DevSecOps (2) Documentation (22) ETL (76) ►Features (213) Adaptive query processing (11) Bulk insert (16) Database mail (10) DBCC (7) Experimentation Assistant (DEA) (3) High Availability (36) Query store (10) Replication (40) Transaction log (59) Transparent Data Encryption (TDE) (21) Importing, exporting (51) Installation, setup and configuration (121) Jobs (42) ►Languages and coding (686) Cursors (9) DDL (9) DML (6) JSON (17) PowerShell (77) Python (37) R (16) SQL commands (196) SQLCMD (7) String functions (21) T-SQL (275) XML (15) Lists (12) Machine learning (37) Maintenance (99) Migration (50) Miscellaneous (1) ►Performance tuning (869) Alerting (8) Always On Availability Groups (82) Buffer Pool Extension (BPE) (9) Columnstore index (9) Deadlocks (16) Execution plans (125) In-Memory OLTP (22) Indexes (79) Latches (5) Locking (10) Monitoring (100) Performance (196) Performance counters (28) Performance Testing (9) Query analysis (121) Reports (20) SSAS monitoring (3) SSIS monitoring (10) SSRS monitoring (4) Wait types (11) ►Professional development (68) Professional development (27) Project management (9) SQL interview questions (32) Recovery (33) Security (84) Server management (24) SQL Azure (271) SQL Server Management Studio (SSMS) (90) SQL Server on Linux (21) ►SQL Server versions (177) SQL Server 2012 (6) SQL Server 2016 (63) SQL Server 2017 (49) SQL Server 2019 (57) SQL Server 2022 (2) ►Technologies (334) AWS (45) AWS RDS (56) Azure Cosmos DB (28) Containers (12) Docker (9) Graph database (13) Kerberos (2) Kubernetes (1) Linux (44) LocalDB (2) MySQL (49) Oracle (10) PolyBase (10) PostgreSQL (36) SharePoint (4) Ubuntu (13) Uncategorized (4) Utilities (21) Helpers and best practices BI performance counters SQL code smells rules SQL Server wait types © 2022 Quest Software Inc. ALL RIGHTS RESERVED. GDPR Terms of Use Privacy
Share:
0 comments

Comments (0)

Leave a Comment

Minimum 10 characters required

* All fields are required. Comments are moderated before appearing.

No comments yet. Be the first to comment!

Reporting in SQL Server Customize the visual appearance of your reports | Trend Now | Trend Now