Doping is one of the most important issues in semiconductor physics. The charge carrier generated by doping can profoundly change the properties of semiconductors and their performance in optoelectronic device applications, such as solar cells. Using detailed balance theory and first-principles calculated defect formation energies and transition energy levels, we derive general formulae to calculate carrier density for semiconductors with multi dopants and multi transition energy levels. As an example, we studied CdTe doped with Cu, in which V Cd, Cu Cd, and Cu i are the dominant defects/impurities. We show that in this system, when Cu concentration increases, the doping properties of the system can change from a poor p-type, to a poorer p-type, to a better p-type, and then to a poor p-type again, in good agreement with experimental observation of CdTe-based solar cells.