Given a complex idempotent matrix A, we derive simple, sufficient and necessary conditions for a matrix X being a nontrivial solution of the Yang-Baxter-like matrix equation A X A = X A X , discriminating commuting solutions from non-commuting ones. On this basis, we construct all the commuting solutions of the nonlinear matrix equation.