SSRS RowNumber Function

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 SSRS RowNumber function, we use the Employee table below grouped by Occupation. The image shows the records in the Table report.

Aggregate Functions Source

SSRS RowNumber function Example

For this, let me add a new column to the left side of the FirstName column.

Add a New Column to the Left Side

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.

Choose the Expression option

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")
SSRS RowNumber Function expression to show row numbers for entire table

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.

SSRS RowNumber Function report to show row numbers for entire table

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")
Expression to show row numbers per group

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.

SSRS RowNumber Function to show row numbers for entire table and group