Friday, May 15, 2015

SSRS: Change Font and Background Color at Run time


SSRS: Change Font and Background Color at Runtime.

Sometimes Clients requirements are very unexceptional but we need to fulfill them. So the requirement is that Client could change the Font properties as per their will like they can change “Font Family, Font Size, Font Style and Background Color of Tablix Header” at any time.

So if N numbers of reports are deployed then “How do you do it”? Solution is given below:

Create a table in Database like Font_Table or whatever the name you want to give. Add columns like: Font_Family, Font_Size, Back_Color etc. Insert only one row in table, if you need more values then add columns but insert only single row as below:

CREATE TABLE FONT_TABLE
(
Font_Family  VARCHAR(50),
Font_Size   VARCHAR(10),
Back_Color   VARCHAR(10)
)

INSERT INTO FONT_TABLE VALUES
('Calibri', 10pt, 'GREEN')


SELECT * FROM FONT_TABLE




NOW, we can use this table values in our SSRS report’s properties. We can write expression of Font Properties and many others as well.
Add new dataset in report. Add query “Select * from Font_Table”


Go to table header -> Properties -> BackgroundColor -> Expressions -> Choose color field as below:


For Font Family:
   




Do it same for Font Size, Font Weight etc.
See the output:




NOW if I change the values in my Font_Table in database and just refresh the report, you will see the difference:

UPDATE FONT_TABLE
SET Font_Family = 'Verdana',
      Font_Size = '12pt',
      Back_Color = 'Orange'







So you can change any property at runtime which having expression functionality and also we can use RGB Code for Color property instead of writing color name. If you use this property at the time of developing reports then all reports will be effected. Enjoy and let me know for any question. Thanks.

SSRS: Break Table Data in Vertical Format

SSRS: Break the Table Data in Vertical Format.

We generally get the requirement to break the table records, so that some specific counts of records appear in each page. For ex- if your table has 100 records and you want to break this table in 20 records each page then we use “Ceiling Function” and add page break BUT if I want to break this table Vertically like below:


This is only a single table which is breaking vertically, so below are some steps to achieve this funcanality.

  1. Create a ROW Group on Tablix and write expression “Ceiling(ROWNUMBER(NOTHING) / 5)
  2. Create COLUMN Group on Tablix and write expression “(ROWNUMBER(NOTHING)  ) mod 5
  3. Add Fields and Lable as below:


  1. You can change Ceiling and MOD value as per choice but if both remain same then it would be good.

Preview the Report and you will get desired output: Thanks.