electromagnet repelling permanent magnet
Not just any current will do to make them repel. The current must be larger than a certain minimum.

As you have correctly noticed, the core and the permanent magnet (PM) are attracted when the current is zero. This means the field from the PM is creating a field in the iron core.

As you increase the current slightly above zero, in opposition to the PM, there will still be sufficient field strength from the PM to magnetise the iron core, just weaker than before. The core and PM will still be attracted.

As you increase the current further, at some point the magnetic field from the coils will exactly oppose that of the PM, and drive the core's field down to zero.

Further increases in the coil current will now magnetise the core in opposition to the PM, which will be repelled.

While there is a formula that is able to calculate how much current is needed to oppose the field of the PM, it not only involves the strength of the PM, but also the spacing to the core, and the geometry of the air space between the core and the PM. Calculating from first principles would be so intractable that the simplest route would be to hang the PM from a string, and measure its deflection as you change the current.