Sorting by groups

Is it possible to do a sort based on a subtotal that occurs every nth line as opposed to every line?