I can't tell you how to do it in IBKR, but there should be an option that allows you to choose which lot you are selling, or an option that allows you to select a method for determining your cost basis... at least these options should be there if your account is based in the USA. Don't know about other countries.
For example, Schwab gives you this screen, with a choice for "specified lots," meaning you choose exactly which shares you are selling.
View attachment 248592
BMK