T-sql – Count rows in dataset SSRS2012

countssrs-2012t-sql

I want to count the number of rows in my result DataSet, I put in my DataSet a calculated field with this expression :

=CountRows("DataSet1")
But I have the following error message:

"The expression used for the calculated field '=CountRows' includes an aggregate, RowNumber, RunningValue, Previous or lookup function. Aggregate, RowNumber, RunningValue, Previous and lookup functions cannot be used in calculated field expressions." What should I do ? thanks

Best Answer

You cannot use an aggregate like CountRows() in a calculated field in your dataset. But you can use CountRows() as an expression in a textbox (alone or within a table) scoped to your dataset. Now that you have your dataset created, you can put a textbox on the report and populate it with the expression =CountRows("DataSet1"), and it will provide the correct answer.

Otherwise, you will need to modify your dataset to include the rowcount. It would seem that using the expression in the report would be the desired option as modiying the dataset would give you a column populated with either a running total or the total rows repeated on each column.