Technique: Counting Rows, Finding First & Last Row in a Report

Modified on Thu, Apr 10 at 6:51 AM

Row Counting & Finding

If you have not done so, read the article on the Column Processing Model.


In order to successfully count rows you must have a field, such as the studentID field when processing students, that is present and not "empty" in every row of the report.   The row counting and first and last row detectors Expression Columns must be run after the sort and all columns which depend on them must occur after the sort.


CAVEAT:  You probably will not be able to use the examples below verbatim.  You will need to make sure the "studentid" field is spelled correctly for the table(s) you are using for your report and, in the case of the "First row in the report" that is found via the row counter, you must make sure it uses the name you actually give your row counter column in your report.



CAVEAT: All of these Columns must be processed after the sort.  And all columns that use these must also be processed after the sort.


Row counter:

${ empty prevRow.studentid ? 1 : prevRow.rows+1}

This locates the very first row in the sorted report by finding the "empty studentId" in the "previous row".  In the very first row of the report, the Column Processing Model acts as if there is an "empty" row in the "previous row".  By looking for the "empty student id in the previous row" the first real row of the report can be found.


To count rows, simply add 1 to the count in the previous row.


First row in a report - if using a row counter:

${ row.rows == 1 }

If you are using a row counter, such as shown above, you will have already found the "first row" of the report.  As long as you place this Column after the "row counter" column (and you name the row counter column "rows"), you can simply test to determine if this is "row #1".  Voila! The first row.  This expression evalutes to a true/false value.  It can be used as a conditional in other columns.


First row in a report - if not using a row counter:

${ empty prevRow.studentid }

If you are not using a row counter, the first row can be found just as shown for the row counter example above:

Locate the very first row in the sorted report by finding the "empty studentId" in the "previous row".   This expression evalutes to a true/false value.  It can be used as a conditional in other columns.


Last row in a report:

${ empty nextRow.studentid }

Similarly, the last row can be found by finding the row where the next row's studentId field is "empty".     This expression evalutes to a true/false value.  It can be used as a conditional in other columns.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article