Partial replacement of Nd by Y and La helps to decrease temperature coefficients of remanent magnetization for Nd2Fe14 B (2:14:1) based magnets. The efficiency of La/Y doping depends on the distribution of La/Y in the multi-phase microstructure of a Nd–Fe–B magnet. To understand and control the La/Y redistribution, the partitioning of La/Y in 2:14:1 and Nd-rich grain boundary phase have been studied by a first-principles density functional calculation. The total energy calculations indicate that La and Y prefer to enter the 4g and 4f sites in the 2:14:1 phase, respectively. The substitution energies of La and Y in 2:14:1 are positive (0.41eV/atom) and negative (−0.38eV/atom), respectively. The results indicate that Y prefers to enter the 2:14:1 phase while La tends to be expelled from 2:14:1 phase to Nd-rich grain boundary phase. This is the thermodynamic origin for the different partition behavior of La and Y in Nd–Fe–B magnets, which affects the magnetic properties.