As other have said here the approach is to go through the item ledger entries and value entries.
But the way you want to go about this can be different if you want to create a report or if you want to create a page that will display this information.
One option can also be to introduce batch handling on items because then you have standard functionality to track items from purchase through sales.
So what is your specific business need and how do you want the data to be reported or displayed?