Sunday, February 19, 2012

Counting rows in a report

i have a report with 1 group and items under the group.

i want to add a new field called Sl. no. at the group level which keeps the count on groups...by that i mean say if there are 10 groups i want the number from 1 to 10 appear against each group as
1 Grp1
2 Grp2
3 Grp3
.
.
.
10 Grp10

How can i achieve the above. I tried the rownumber but it returns the number of rows the group has. The levels i have is "table1" the main scope and "table1_Group1" the group scope which in the table1 scope.

Any help will be appreciated.

what you are doing is similiar to what I wanted to do to get a generic counter... someone else had posted the below as an answer for me. This should work for you as well.

Put this in your code window:

Dim numGroupRow as Double

Function GetRowNumber() as Double
numGroupRow += 1
Return numGroupRow
End Function

Then put this in your group row textbox

= Code.GetRowNumber()

This will increment every group row. If you need to start over at some point the code will need to change.

|||thanks for ur reply.
It works as desired but i have some sorting defined on a field and i want to this sl.no field to move with the sort.

I will try to alter the code but if the solution is out there i would love to have it.

Thaks
|||

I don't think sorting should matter as this is a generic counter and is only incremented by 1 when you call it.

Since the sort acts before the fields are displayed, it shouldn't matter.

|||I thought so too but it is not sorting with the other fields. This is what happens the initial report comes as:

1....valA.......valB
2....valC.......valD
.
.
.
.
40...valE......valF
41...valG.....valH

now when i sort on first field the output comes as

1...valE......valF
2....valC.......valD
3....valA.......valB
.
.
.
.

41...valG.....valH

instead of
40...valE......valF
2....valC.......valD
1....valA.......valB
.
.
.
.

41...valG.....valH
|||

ah, I see.

That is becuase the counter is working as expected.

you will probobaly have to create a field on the dataset your self, add a new field and refernce the code in your field.

then place that field on your report and try the sort that way. You may have to play around with some grouping.

No comments:

Post a Comment