Tuesday, March 10, 2009

Row number for grouped data

Rownumber function returns the number of the row of the dataset

EMP_NAME
Emp1
Emp2
Emp3
Emp3
Emp3
Emp4

If we would like to groupby EMP_NAME and show the row number beside each row, the result will be :

Row number EMP_NAME
1 emp_1
2 emp_2
3 emp_3
6 emp_4

As you can see the row number value is not correct, actually it is correct because the rownumber function returns the number of row inside the dataset not inside the grouped data in the report

Now we need to display the row number for what we see in the report instead of what is inside the dataset

I am going to use runningvlaue function for the grouped data inside "table1"

=runningvalue(Fields!EMP_NAME.Value,countdistinct,"table1")

Result:

Rownumber EMP_NAME
1 emp_1
2 emp_2
3 emp_3
4 emp_4

Runningvalue function: accumulates the result of any aggregate function except for rownumber and runningvalue.

No comments:

Post a Comment