Experimental measurements for the conversion loss between electric and mechanical energies of (Mg,Zn)O-based resonators show that Mg substitution can improve the electromechanical coupling of the wurtzite ZnO films up to the substitution concentration of 35%. Extended x-ray absorption fine structure (EXAFS) experiments indicate that both Mg and Zn exhibit tetrahedral local structures in (Mg,Zn)O films. With an increase in the Mg substitution concentration, the Zn-O bond length shows a slight tendency to increase and the Mg-O bond length practically remains the same. Further analysis of the EXAFS spectra reveals that a ${\mathrm{MgO}}_{4}$ tetrahedron cluster exists in the oxide alloy. First-principles calculations reproduce the experimental results, suggesting that the enhanced electromechanical coupling is mainly attributed to a decrease in the dielectric constant due to the Mg substitution. The enhancement in piezoelectricity caused by Mg substitution originates from an increase in the Zn-O bond length along the $c$ axis, which enhances the $c$-axis-oriented electric dipole moment. Furthermore, the calculations show that the Mg substitution can reduce the critical transition pressure from the wurtzite phase to the rocksalt phase. This study shows that combining the EXAFS experiment and theoretical calculation is a reliable method for understanding the relationship between the electromechanical coupling and local cation structure in wurtzite alloy systems. This can guide the search for novel piezoelectric materials.