Transconductance of a MOSFET
The basis is the following approximate equation for the drain current (Wikipedia):



Taking the partial derivative gave gm as a function of (Vgs-Vth). One can express (Vgs-Vth) as a function of Id reversing the base equation. By inserting that one gets your problematic third line.