Professional Documents
Culture Documents
PRASHANT
Contents
Introduction to ssrs......................................................................................................................................................................... 3
Section A......................................................................................................................................................................................... 3
How to install ssrs........................................................................................................................................................................... 4
Built in Expressions or functions used in ssrs............................................................................................................................... 10
Types of Expressions..................................................................................................................................................................... 10
GLOBALS....................................................................................................................................................................................... 11
OPERATORS............................................................................................................................................................ 11
COMMON FUNCTIONS................................................................................................................................................................... 12
SECTION B.................................................................................................................................................................................... 14
EMBEDDED CODE FOR CELL COLORING (CONDITIONAL FORMATTING)...................................................................................... 15
SHOW PERCENTAGES ON PIE CHART............................................................................................................................................ 17
T-SQL ISNULL FUNCTION EQUIVALENT........................................................................................................................................ 20
SHOW TICK/CROSS BOX INSTEAD OF TRUE/FALSE OR 1/0......................................................................................................... 20
LINK POSTCODE OR ADDRESS TO GOOGLE MAPS....................................................................................................................... 22
HANDLING DIVIDE BY ZERO ERROR........................................................................................................................................... 24
PARAMETER TO CONTROL ROW/COLUMN/TABLE VISIBILITY....................................................................................................... 25
ALTERNATING ROW COLORS IN A TABLE...................................................................................................................................... 28
HAVE TEXT ON MULTIPLE LINES IN A TEXTBOX........................................................................................................................... 28
HOW TO HAVE INDENTED TEXT IN A REPORT.............................................................................................................................. 29
DEFINE A REPORT CONSTANT....................................................................................................................................................... 30
DISPLAY A MESSAGE WHEN REPORT RESULT SET IS EMPTY........................................................................................................ 31
SETTING PARAMETERS DEFAULT VALUE ISSUE............................................................................................................................ 33
1 | Page
2 | Page
INTRODUCTION TO SSRS
SSRS or SQL server Reporting Services which is also called Microsoft SQL reporting, is a component of the Microsoft BI
stack.
The Microsoft Business Intelligence Stack mainly consists of SQL Database Engine, SSRS, SSAS, SSIS and other tools
SSRS is a set of readymade tools, which help you to create, deploy and manage reports.
Microsoft SSRS or Business Intelligence SSRS, lets you create very rich reports (Tabular/Graphical/Interactive/free-form)
from various data sources with rich data visualization (Charts, Maps, sparklines).
SSRS allows are reports to be exported in various formats (Excel, PDF, word etc.)
SSRS allows reports to be delivered via emails or dropped to a share location in an automated fashion.
SSRS provides a host of security features, in order to control, who sees which reports etc.
3 | Page
SECTION A
HOW TO INSTALL SSRS
Double-click the SQL Server 2012 installation media. Click the Installation link on the left to view the Installation options. Click the top
link New SQL Server stand-alone installation or add features to an existing installation.
Follow the SQL Server Setup wizard until you get to the Installation Type screen. At that screen, select Add features to an
existing instance
of
SQL
Server 2012.
Click Next to
move
to
the
Feature
Selection page.
Select Reporting
Native and SQL Server Data Tools. If the Management Tools have not been installed, go ahead and choose them as well.
4 | Page
Services
Continue through the wizard and reboot the computer at the end of the installation if instructed to do so.
SQL
Manager > Connect on the Reporting Services Configuration Connection dialog box.
5 | Page
Services
Configuration
On the left-hand side of the Reporting Services Configuration Manager, click Database. Click the Change Database button on the right side
of the screen.
6 | Page
7 | Page
Click through the rest of the wizard accepting the defaults. This wizard creates two databases: ReportServer, used to store report definitions
and security, and ReportServerTempDB which is used as scratch space when preparing reports for user requests.
Now click Web Service URL on the left-hand side of the Reporting Services Configuration Manager. Click the Apply button to accept the
defaults. If the Apply button has been grayed out, move on to the next step. This step sets up the SSRS web service. The web service is the
program that runs in the background that communicates between the web page, which you will set up next, and the databases.
8 | Page
The final configuration step is to select the Report Manager URL link on the left. Accept the default settings and click Apply. If
the Apply button was already grayed out, this means the SSRS was already configured. This step sets up the Report Manager web site where
you will publish reports. You may be wondering if you also must install a web server on your computer. SQL Server does not require that the
Internet Information Server (IIS), the Microsoft web server, be installed to run Report Manager.
9 | Page
Click Exit to dismiss the Reporting Services Configuration Manager dialog box.
Globals
Common Functions - Text, Date & Time, Math, Inspection, Program Flow, Aggregate, Financial, Conversion, Miscellaneous
10 | P a g e
GLOBALS
Global expressions executes/works in Page Header and Footer parts only.
ExecutionTime shows date and time at when report executes
PageNumber shows page number of each and every page but allowed only in page header and footer
ReportName displays name of the active report what name we have assigned to the active report
UserId shows current user name like saxony/Prashant.Rai
Language displays language like US-English
OPERATORS
Arithmetic
^ power of
* multiplication
/ divides two numbers and returns a floating point result
\ divides two numbers and returns a integer result
Mod divides two numbers and returns remainder only
+ adds two numbers and concatenation for two strings
- subtraction and indicates negative value for numeric values
11 | P a g e
Comparison
Known operators : < <= > >= <>
Like compares two strings and return true if matched or else returns False. Ex: =Fields!Title.Value Like Fields!LoginID.Value
Is compare two object reference variables Ex: = Fields!Title.Value Is Null
Concatenation
+ and & symbols uses for concatenation
Logical
Known: And, Not, Or
Xor SELECT * FROM users where firstname = 'Prashant' XOR lastname = 'Rai'
AndAlso First condition will check first and if it is true only, goes to next or else it won't need to check. Because our execution time is saving
in a logical operation in which more conditions is combined using AndAlso function.
OrElse same like above
COMMON FUNCTIONS
The rest of the functions can be accessed by clicking on Expression on any report item, which looks like following:
12 | P a g e
13 | P a g e
SECTION B
The following section (pg.16-pg.46) will introduce you to some tips and tricks which are based upon,
basic/inbuilt functions and expressions that we have in SSRS and which I have garnered over a
period of time. This section is recommended for anyone who wants more out of standard SSRS
expressions.
14 | P a g e
15 | P a g e
End Function
Now Insert either of these formula into the Cells Colour Format
=Code.GetColour(Fields!TotalDue.Value)
=Code.GetColour(Me.Value)
16 | P a g e
Now click the Edit button for the Values section and go to the Point Labels tab
17 | P a g e
Uncheck Auto to get percentages on outside (the inside square of 9 put labels in Pie Chart, the other are on the outside) and check the Show
point labels box
Now the formula to enter into the Data label text box is:
=Sum(Value) / Sum(Value, "ChartDataset")
In this case the formula is:
=Sum(Fields!TotalDue.Value) / Sum(Fields!TotalDue.Value, "pRepSalesOrdersByMonth")
And the Label Style button opens up the label formatting properties
18 | P a g e
19 | P a g e
20 | P a g e
SQL
,CASE
WHEN BooleanField = 1
THEN 'R'
ELSE 'Q'
END AS BooleanField
IIF Expression
=IIF(Fields!BooleanField.Value = True, "R", "Q")
The original field doesn't necessarily have to be Boolean e.g. Does final score pass exam:
=IIF(Fields!FinalScore.Value >= 50, "R", "Q")
Now just format the textbox to Wingdings2
21 | P a g e
22 | P a g e
Open the Go to URL expression builder and insert the following expression:
="javascript:void(window.open('http://maps.google.com/maps?q=" & Fields!PostalCode.Value & "','_blank','scrollbars=auto,
resizable=yes, status=no'))"
This will open google maps in a new IE window using the results of the field as the search criteria
Click here for more info on the javascript open method
Or alternatively you can use the expression without the javascript to open in the current IE
="http://maps.google.com/maps?q=" & Fields!PostalCode.Value
23 | P a g e
This is just one application of the Jump to URL functionality, this can be used in many ways, e.g. Linking to customer or supplier websites
(providing you have the website address as a field in reports dataset)
Now go to the Code tab and write (or copy and paste) in this code:
Function CalculateFraction(ByVal Numerator As Double, ByVal Denominator As Double) As Double
If Denominator = 0 Then
CalculateFraction = 0
Else
CalculateFraction = Numerator / Denominator
End If
Return CalculateFraction
End Function
24 | P a g e
Now insert the following expression into the desired textbox and format according:
=Code.CalculateFraction(Fields!Numerator.Value, Fields!Denominator.Value)
You could also use the following IIF expression:
=IIF(Fields!Denominator.Value = 0, 0, Fields!Numerator.Value / IIF(Fields!Denominator.value = 0, 1, Fields!
Denominator.Value))
But the best thing about using the Embedded Code it's easier to use and reusable.
25 | P a g e
26 | P a g e
27 | P a g e
The same can be done to control the visibility for rows and the entire table.
28 | P a g e
To handle this we can embed a non truncating space character by using an ASCII key combination code. To embed this ASCII key code we
would hold the ALT key, type 0160 and then let go of the ALT key.
So to do this in our report, in the Reporting Services table, right click on the textbox with the problem, select (fx) Expression. Then in the Edit
Expression editor use the REPLACE function to embed the non-truncating space with the normal one as follows:
=REPLACE(Fields!Rank.Value," "," ") -- (The first value between the double quotes is a space and the second value between the double quotes
is the ALT-0160 combination code.)
29 | P a g e
After we have made this function change and redisplay the report our hierarchy should be displayed properly as needed.
30 | P a g e
31 | P a g e
32 | P a g e
Now when you preview the report in the design environment this parameter will default to 1 and if you deploy this report to Report Manager
and view it from there it will also default to 1.
The problem arises when you want to change it, if in the example you wanted to change the default value to 0 and you just replaced the 1
with a 0 then when you preview in the design environment the report will recognise this change and default to 0 but when you deploy the
report it will still default to 1 (the value it was set to when it was first deployed)
This is easily fixed you just need to include and equals sign first.
Now when you re-deploy the report it will update the RDL on the Report Server.
For text (and dates, although using expression it better for dates) you just need to use marks e.g.
33 | P a g e
="Yes"
34 | P a g e
Now bring up the textbox properties for the far left textbox in the newly created Continent group and set the Value to Fields!Continent.Value
and the Name to Continent
If (for example) your dataset when down to individual Invoice level you could add more columns to the right and then put the Invoice details
(Date, Reference Number, Customer etc) on the detail line
35 | P a g e
Note: You can only use Aggregate functions on the Groupings lines (other than the Field its been grouped on)
Now to give the table the drill-down effect you need to set each rows visibility to Hidden and the Toggle Item to the textbox above, so for the
detail row we set the Toggle Item to the OrderYear textbox (OrderYear row to Name, Name row to Continent) click on the Detail row to get
the properties
If you want to have totals (at the bottom) for each grouping these would go in the groups below the detail line and these would also need to
have their visibilities set, I usual just delete them.
One effect I like the look of is to indent each group (more than the other) by change the textbox Left property on the Format tab:
36 | P a g e
Once these have all been set you ready to deploy and it should look something like:
37 | P a g e
Let's change the Height to 0 Under InteractiveSize Property under Report properties and deploy our report and see if it is showing all records
on one page.
38 | P a g e
Report display
As we can see that the next page button is not available as all the records are shown on one page.
39 | P a g e
Note:
Displaying all the records on one page can take long time to display. You want to make sure you do not have millions of records to shown on a
page. In those cases the explorer can crash or can take forever to display. Instead of displaying all the records on one page you might want to
increase Height from 11 inches to another number to display more records on each page.
HANDLING PAGING AND NO DATA ISSUE IN A SUB-REPORT
1.
Paging
When creating a report with sub reports paging should be added to the top level report. The paging inside the sub report looks fine on screen
but is ignored when exporting to PDF.
2.
No Data
When there is no data in a sub report the report will not show. If you have a report where you have paging between sub-reports you will end
up with a page break, but then no report, which means you get an empty page in your report. The way to force you report to render is to
create an empty dataset, with
1
select 1
as the SQL. This will always execute and force the sub-report to always render
40 | P a g e
In addition to the overall comparison of totals between schools, the exact percentage for each school is also useful information. To keep this
chart uncluttered, let's choose to provide the exact percentage using a tooltip.
Right-click the chart, select Series Properties, and open the tooltip expression (fx) window. This expression uses the Fields Collection (i.e.,
the data) as well as text:
Regarding the FormatNumber function: source data is stored as decimal(10,2) which translates perfectly for display on the X axis when the
axis is formatted as a percentage. However, that data type doesn't look very nice in a label. To handle this, first multiply it by 100 (which
took .81 to 81.00), then used the FormatNumber function with 0 decimal places (which took my 81.00 to 81), and finally concatenated the %
symbol along with some descriptive text.
41 | P a g e
42 | P a g e
43 | P a g e
function : The name of the aggregate function to apply to the expression, for example- Sum.
See the table below and RunningTotal column which is Cumulative SUM of Quantity column.
Quantity RunningTotal
2009-02-01 12:06:16.820
10
10
2009-02-02 16:16:16.820
15
25
2009-02-01 13:26:16.820
20
45
2009-02-03 17:40:16.820
12
57
2009-02-04 13:05:16.820
15
72
2009-02-03 14:25:16.820
25
97
2009-02-04 15:50:16.820
50
147
2009-02-05 19:40:16.820
30
177
2009-02-06 15:30:16.820
20
197
10
2009-02-07 16:20:16.820
10
207
11
2009-02-05 17:05:16.820
35
242
For achieving that in SSRS, add extra column in your Reports Layout Page and put following expression in it=RunningValue(Fields!Quantity.Value, Sum, Nothing)
44 | P a g e
But what about when you want the RunningTotals for group of records? Like for above example you want the Running Totals for each orderId
separately. See the table below :
Quantity RunningTotal
2009-02-01 12:06:16.820
10
10
2009-02-02 16:16:16.820
15
25
2009-02-01 13:26:16.820
20
20
2009-02-03 17:40:16.820
12
32
2009-02-04 13:05:16.820
15
47
2009-02-03 14:25:16.820
25
25
2009-02-04 15:50:16.820
50
75
2009-02-05 19:40:16.820
30
105
2009-02-06 15:30:16.820
20
20
10
2009-02-07 16:20:16.820
10
30
11
2009-02-05 17:05:16.820
35
35
Give some name to the group. If you dont gave any name the default name
would be something like table1_Group1. Just note that. And add OrderId to Group On expression.
45 | P a g e
Well after adding the extra group in the report you might see blank spaces after every OrderId change. If you dont want those blanks and
want continuous report, then go to the property page of the new group added and set Visible to false.
REPEAT TABLE HEADER ON EACH PAGE IN SSRS
In this scenario, we have to set the some properties of static member of the row groups.
To see the static members of the row groups of the tablix, select tablix and click on the small drop down arrow on the right side of the Row
Groups/Columns Groups header. Then select Advanced Mode.
Please see below screenshot.
Now you can see the static members of row groups. Now select 1st static member. After selecting 1st member, top left cell of the tablix will
be selected in the report designer.
Now press F4 or manually open property page. In that, set propertyRepeatOnNewPage to True. Also set KeepWithGroup property
to After.
46 | P a g e
Now run your report. You will see that your table header will repeat on every page of report.
If still issue is not solved then set FixedData property to True in property page of first static member in row group. It will reproduce table
header on every page of report.
Sometimes you dont need to set all three properties, but it doesnt do any harm so lets set all three properties.
47 | P a g e
48 | P a g e