group_records function

Group records