Combine flat rows of data by grouping them