Lets see what is RowNumber function in SSRS and a simple example to demonstrate the same. This RowNumber function returns the row number for every row with in the dataset. You have to pass the scope for which you wish to create row numbers. PFB the syntax for the same –
Scope – This tell the server when to RESET the running count. If you pass DATASET name as SCOPE then it will not RESET until the all the items in the DATASET get over. Similarly if you secify a GROUP then the running count will not reset until all the rows items in the group is completed and it will repeat the same for all the groups. You can provide anyone of the below given objects as SCOPE of the function.
If you provide NOTHING then it will take the OUTERMOST data region and will provide Running Count of the rows. Lets see an example on how to to get the Row Number of a SSRS report using ROWNUMBER Function. PFB the expression I am using to get the row number of each row of the data region.
PFB the SC which displays the output of the expression given above.
You may be wondering “Why I need this ? ” and the answer is – There are many scenarios where you need this and lets discuss about one here. Lets say my requirement is to COLOR alternate rows in one color and in this case I can make use of ROWNUMBER Function to achieve the same. PFB the expression I have to use to achieve the given requirement.
=iif(RowNumber(Nothing) Mod 2,”Green”,”Yellow”).
PFB the steps you have to follow to achieve the same.
1) Select entire row.
2) Press F4(Properties Window).
3) Select BackColor Property and click on Expression.
4) Add the above given expression as shown below.
5) Preview report and you can see the report like given below.
You can use the same expression in many places like for changing font color,font weight,border color … So this is very useful function in designing your report.
That’s it, Happy Coding !!
Roopesh Babu V