The SSRS RowNumber function is a Miscellaneous function that will return a running count (row number) of all the available rows in a given scope (DataSet or Group). The syntax of the RowNumber function to show the continuous numbers or row numbers within a group or table is as shown below.
=RowNumber("DataSet_Name")
=RowNumber("Group_Name")
To demonstrate the RowNumber function, we use the Employee table below grouped by Occupation. The image shows the records in the Table report.
SSRS RowNumber function Example
For this, let me add a new column to the left side of the FirstName column. So, select the FirstName portion and right-click on it, select teh Insert Column, and then choose Left.
Next, right-click the textbox under it and select the Expression option. To understand the report, I suggest you refer to the articles on charts, tables, grouping, More Functions, and format tables in SSRS.
It opens the following expression window to return row numbers. The SSRS RowNumber function below will return the row numbers for the entire table, starting from 1 to n.
=RowNumber("DSet")
You can also use the Nothing instead of DataSet. However, we recommend using the DataSet name.
=RowNumber(Nothing)
Similarly, create one more column to show the row number in each group. The RowNumber function expression below returns row numbers for each occupation group. This means that the number will restart for each group.
=RowNumber("Occupation")
The below report preview shows the row numbers for the entire table and each group.
Apart from the above functionality, you cause the SSRS RowNumber function to assign the alternative row colors to the grouped table report. For this, select the details row and go to the BackgroundColor in the property window. Next, choose the expression option and write the below expression to change the alternative row background colors using RowNumber.
=IIf(RowNumber("Occupation") Mod 2 = 0, "Gold", "Pink")
Please click the preview tab to see the RowNumber report. For more information, refer to the Add Row Numbers to a Report and Row Numbers to Group articles.