You may have bought different quantities of a stock (share) at different prices (over time). In the case of Multiple BUY and SELL Delivery transactions in 1 stock, the SELL Quantity is first adjusted against the Oldest BUY Transaction. This method is also called FIFO (First In First Out).
Profit & Loss in Shares is taxable. So, to calculate the right profit & loss which can be bifurcated between Short Term Capital gain and Long Term Capital gain, we need to apply FIFO (First In First Out):
Average Buy Price = Rs. 781
FIFO simply means that when you sell any shares, they will be sold from the units you bought first. For example, in the case above, 15 shares sold on 9 April 2018 will be the shares you had bought on 15 Jan 2018 (these were the first 15 shares you bought).
Similarly, 20 shares on 14th June 2018 are the ones that were bought on 16 March 2018.
The average price is calculated on the basis of the number of shares left after all the sell transactions have been adjusted against the buy transactions (while following FIFO).
In this example, there are 15 shares left (bought on 3 May 2019) and the price of that is Rs. 781. The average buying price here is Rs. 781.