In the European Union’s Energy Performance of Buildings Directive, the energy efficiency goal for buildings is set in terms of primary energy use. In the proposal from the National Board of Housing, Building, and Planning, for nearly zero energy buildings in Sweden, the use of primary energy is expressed as a primary energy number calculated with given primary energy factors. In this article, a multi-dwelling building is simulated and the difference in the primary energy number is investigated when the building uses heat from district heating systems or from heat pumps, alone or combined with solar thermal or solar photovoltaic systems. It is also investigated how the global CO2 emissions are influenced by the different energy system combinations and with different fuels used. It is concluded that the calculated primary energy number is lower for heat pump systems, but the global CO2 emissions are lowest when district heating uses mostly biofuels and is combined with solar PV systems. The difference is up to 140 tonnes/year. If the aim with the Swedish building code is to decrease the global CO2 emissions then the ratio between the primary energy factors for electricity and heat should be larger than three and considerably higher than today.