I first copy data into a blank Excel workbook and sort it by column D, then A, and then B.
I then use the subtotal function to sum the column D at each change in column C. Then I subtotal again summing the column C at each change in A. And finally summing C at each change in B.
The final result looks like this example:

Column A Column B Column C Column D
ITEM A B 2 EXAMPLE100
B Total 2
ITEM A S 1 EXAMPLE100
S Total 1
ITEM A Total 3
ITEM B B 2 EXAMPLE100
B Total 2
ITEM B S 3 EXAMPLE100
S Total 3
ITEM B Total 5
8 EXAMPLE100 Total

For some reason this used to work without a problem. And now it inserts the total in the wrong rows.

Like so:

Column A Column B Column C Column D
ITEM A B 2 EXAMPLE100
B Total 2
ITEM A S 1 EXAMPLE100
ITEM A Total 3
S Total 1
ITEM B B 2 EXAMPLE100
B Total 2
ITEM B S 3 EXAMPLE100
ITEM B Total 5
8 EXAMPLE100 Total
S Total 3


I can't figure out how to fix this problem.
I use Microsoft Excel 2003. And I've tried this on numerous computers, all of which have the same result.
If anyone knows why, what format the data needs to be in, or any reason this sorts the totals in this manner, please let me know. I've been working on fixing this for 2 months now.
Thank you.