Translate ending stock quantity

Dear Experts,

Please help me for below case:

My ending stock balance (in quantity)of item a1 = 2,506 pcs.

During the year, we made a lot of purchases. If just have a look in one item a1, we can have the end balance is comprised of most recent purchase of 1,730 pcs in Nov 2014; 25 pcs in Oct 2014 and 751 pcs bought in Sep 2014.

Can you please help me to develop a formula to verify how many a1 remained from which month of purchase.

Attached file is more example for this case.

Much appreciate for your urgent help :(

Thanks so much

AttachmentSize
To ask formular.xlsx14.69 KB