This paper proposes a novel current controller for selective harmonic compensation in microgrids using active power filters (APFs). The method aims to improve power quality by reducing total harmonic distortion (THD) and has shown superior results through MATLAB simulations and practical implementation on a 12-bus microgrid. Tests confirmed that the proposed controller effectively compensates for current harmonics, thus enhancing overall performance in a renewable energy context.