@alien4u I don't have an example handy but the theory is: sort the lines by the field you want to group by, assign temporary variables for lastGroup and subtotal. Each iteration, increment the subtotal and check if this line's field has changed from lastGroup - if so print and reset the subtotal etc.