The paper proposes a solution for the problem of optimizing medium voltage power systems which supply, among others, nonlinear loads. It is focused on decision tree (DT) application for the sizing and allocation of active power filters (APFs), which are the most effective means of power quality improvement. Propositions of some DT strategies followed by the results have been described in the paper. On the basis of an example of a medium-voltage network, an analysis of the selection of the number and allocation of active power filters was carried out in terms of minimizing losses and costs keeping under control voltage total harmonic distortion (THD) coefficients in the network nodes. The presented example shows that decision trees allow for the selection of the optimal solution, depending on assumed limitations, expected effects, and costs.