Please see this help.sap.com link:
Valuation For A Single Batch - Logistics General (LO) - SAP Library
Please see the paragraph starting "In the following exercises you will create two purchase orders with different prices for the same material. You then post the goods receipt to different batches. You then check the prices at plant level and batch level".
We considered this solution in a project and the pre-requisite material master data settings were nt in line with our business requirements. Hence we wrote custom code based on certain assumptions to calculate cost of a batch.