Show Group Wise Record Numbers in Crystal Report

In crystal report with groups if we add record numbers then it show record number considering all rows not group wise. To overcome this problem and to show record numbers according to groups follows  these steps.
 
Consider the following Employees table.
 
 
 
Step 1: Design report as below. With groups based on Department column.
 
 
 
Step 2: Now add new formula field "Formula1" and in formula editor write below code. 
  1. WHILEPRINTINGRECORDS;   
  2. GLOBAL NUMBERVAR SerialNumber;   
  3. SerialNumber := 0;   
Step 3: Add "Formula1" field in group header section. And suppress it like below.
 
 
 
Step 4: Create another formula field as "Formula2". And Write below code. 
  1.  WHILEPRINTINGRECORDS;   
  2. GLOBAL NUMBERVAR SerialNumber;   
  3. SerialNumber := SerialNumber + 1;   
Step 5: Add this formula field in details section. And change its header as "Sr. No" as below.
 
 
 
Step 6: As in "Formula2" we returning number variable by default shows number in decimal format. To avoid this right click on "Formula2" field. Then go to Format Object option and change number format.
 
Step 7: Save report and Preview it.