Average cost is the total amount paid divided by the total shares. Each lot contributes shares times price. A later purchase at a higher price pulls the average up. A later purchase at a lower price pulls it down. The page combines the lots you enter into one average.
100 shares at $40 and 100 shares at $60 cost $10,000 together. The average cost is $50 a share. Selling above $50 is a gain on that average. Selling below it is a loss.
Commissions are included only if you folded them into the prices you typed. The tax on a sale is the capital-gains page, not this one.