Here is the sample data:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Gender[/TD]
[TD]Material[/TD]
[TD]QTY[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-11[/TD]
[TD]250[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-12[/TD]
[TD]1500[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-13[/TD]
[TD]1000[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-14[/TD]
[TD]4500[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-15[/TD]
[TD]2500[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-16[/TD]
[TD]245[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-17[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-18[/TD]
[TD]4900[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-19[/TD]
[TD]2500[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-20[/TD]
[TD]100[/TD]
[/TR]
</tbody>[/TABLE]
Want it to be organized by gender, then material, grouped in qty of 5000 units max
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Gender[/TD]
[TD]Material[/TD]
[TD]QTY[/TD]
[TD]Group[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-19[/TD]
[TD]2500[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-12[/TD]
[TD]1500[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-13[/TD]
[TD]1000[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-18[/TD]
[TD]4900[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]women[/TD]
[TD]MAT-20[/TD]
[TD]100[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-14[/TD]
[TD]4500[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-11[/TD]
[TD]250[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-16[/TD]
[TD]245[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-17[/TD]
[TD]5[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]men[/TD]
[TD]MAT-15[/TD]
[TD]2500[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]
Hope this clarifies it!