This formula it's a bit long, but I think it works: https://sudapollismo.substack.com/p/fifo-capital-gains-excel-formula