The two costs being compared
Leave the balance where it is and it charges your current APR every month for the whole promo window - interest that grows as the unpaid balance compounds on itself. Move it and you pay the transfer fee up front, then nothing in interest for the promo period. Those are the only two money flows the page models.
So the comparison is simple: the interest the old card would have charged over that window versus the fee the new card charges to stop it. Whichever is smaller is the cheaper path on the money, and everything else - the monthly payment, the balance, the length of the window - is held equal so the fee and the avoided interest are the only things allowed to differ.