Business Intelligence Blogs

View blogs by industry experts on topics such as SSAS, SSIS, SSRS, Power BI, Performance Tuning, Azure, Big Data and much more! You can also sign up to post your own business intelligence blog.

User Preferences and Styling

  • 28 July 2010
  • Author: briankmcdonald
  • Number of views: 7455
  • 0 Comments

Last year, I wrote an article with the same title for another site and as with others, I want to get as many people to see my writings as possible. As such, I am going to post the article here. This was created for SQL Server Reporting Services 2005, but a similar method could be used for SSRS 2008. 

The thought of each of us seeing the same exact thing can sometimes seem daunting and boring to users, which can lead to lack of absorption into the user community. Users often desire to be a little unique (or at least different than those sitting around them). As such, here is a way to allow reporting to pull user color preferences and render them in their desired color scheme.

 

1. Let's begin by setting up our table that will contain our color schemes: 

CREATE TABLE SSRS_Styles
(
 StyleID INT PRIMARY KEY IDENTITY(1,1)
 , StyleName VARCHAR(50)
 , ReportBGColor VARCHAR(100)
 , ReportTitleColor VARCHAR(100)
 , TableHeaderBGColor VARCHAR(100)
 , TableHeaderFontColor VARCHAR(100)
 , TableDetailsBGColor VARCHAR(100)
 , TableDetailsFontColor VARCHAR(100)
)

 

* More values could be stored in this table as I am just using a few of the properties from the body and table objects *

 

2. Now I'm going to add a few standard color schemes into the table: 

--Standard Theme 1
INSERT INTO SSRS_Styles
 (StyleName, ReportBGColor, ReportTitleColor, TableHeaderBGColor
 , TableHeaderFontColor, TableDetailsBGColor, TableDetailsFontColor)
VALUES ('Standard Mono-Chrome','White','Black','#6ca6cd', 'White', 'White','Black')

--Standard Theme 2
INSERT INTO SSRS_Styles
 (StyleName, ReportBGColor, ReportTitleColor, TableHeaderBGColor
 , TableHeaderFontColor, TableDetailsBGColor, TableDetailsFontColor)
VALUES ('Standard Go-Green','White','Green','PaleGreen', 'Black', 'White','Black')

--Standard Theme 3
INSERT INTO SSRS_Styles
 (StyleName, ReportBGColor, ReportTitleColor, TableHeaderBGColor
 , TableHeaderFontColor, TableDetailsBGColor, TableDetailsFontColor)
VALUES ('Standard McPorting','White','Blue','Red', 'White', 'White','Black')

--Standard Theme 4
INSERT INTO SSRS_Styles
 (StyleName, ReportBGColor, ReportTitleColor, TableHeaderBGColor
 , TableHeaderFontColor, TableDetailsBGColor, TableDetailsFontColor)
VALUES ('Standard Star Wars','Black','Silver','Gold', 'Black', 'Black','Silver')

 

The records now in the table should be as follows:

Results

  

3. Now in order to make this work we need to store the preference for a particular user in another table: 

CREATE TABLE SSRS_Style_Preferences
(
 PreferenceID INT PRIMARY KEY IDENTITY(1,1)
 , UserName VARCHAR(50)
 , StyleID INT
 , DateLastModified SMALLDATETIME DEFAULT GETDATE()
)

 

4. Insert some users and their preferences (a web form or report could be used to allow the user to change this setting later, but assigning StyleID = 1 as the default will set the report to the mono-chrome standard). 

INSERT INTO SSRS_Style_Preferences (UserName, StyleID) VALUES ('Default',1)
INSERT INTO SSRS_Style_Preferences (UserName, StyleID) VALUES ('GreenMan',2)
INSERT INTO SSRS_Style_Preferences (UserName, StyleID) VALUES ('BrianMcDonald',3)
INSERT INTO SSRS_Style_Preferences (UserName, StyleID) VALUES ('DarthVader',4)

 

The records now in the SSRS_Style_Preferences table should be as follows:

new results

5. Now it is time to switch over to Business Intelligence Development Studio (BIDS) to edit the report to use the "consumers" preferences.

Note that an assumption is made that the author of the report can create a report and return a resultset into a table control. So from within the report, we need to add two text boxes and a table control. Then we need to set some of the property values of the objects as follows:

Body
BackgroundColor = Fields!ReportBGColor.Value

ReportTitle Textbox (shows the title of the report)
BackgroundColor = Fields!ReportBGColor.Value
Color = Fields!ReportTitleColor.Value


CurrentUserPreference Textbox (shows what user was passed in and their preferred style)
BackgroundColor = Fields!ReportBGColor.Value
Color = Fields!ReportTitleColor.Value

Table
TableRow1 (header) BackgroundColor = Fields!TableHeaderBGColor.Value
TableRow1 (header) Color = Fields!TableHeaderFontColor.Value
TableRow2 (detail) Backgroundcolor = Fields!TableDetailsBGColor.Value
TableRow2 (detail Color = Fields!TableDetailsFontColor.Value

 

6. Preview the results for each user:

Screenshots

For my report, I set the available values of the report parameter to a query and got a listing of the usernames from the SSRS_Style_Preferences table. I have included the database object setup script and the rdl file that I created during this process for your enjoyment. Download them here.

 

Until next time, “keep your ear to the grindstone” – Good Will Hunting

 

 

Brian K. McDonald, MCDBA, MCSD
Business Intelligence Consultant – Pragmatic Works Consulting

Email: bmcdonald@pragmaticworks.com | Blog: BI Developer Network

Convert with DTS xChange  | Develop with BI xPress  | Process with TaskFactory | Document with BI Documenter

 

Print
Categories: Reporting Services
Tags:
Rate this article:
5.0

briankmcdonaldbriankmcdonald

Other posts by briankmcdonald

Please login or register to post comments.