The first time I had that problem, on a DA40, it was fixed by replacing the right hand aileron to eliminate its steel counterbalance, and moving the magnetometer further out in the wing (see RSBD4-052/3
here). However, it's started again, so this time I'm having the wiring to the magnetometer checked. Of course, it's behaved perfectly since I booked it in, but I'll let you know if they find anything.