Under the EU blue card scheme you are allowed to leave the country for a temporary absence of less than 12 months without affecting the blue card validity of the blue card, and hence can return and continue at any stage.
During this period however you would be expected to continue to keep your primary residency in Germany which means:
- Continue to pay German tax on your worldwide income
- Continue to maintain your property in Germany
- Continue to pay health insurance in Germany
This period may be extendable upon specific agreement in advance with the Ausländerbehörde Amt(ABH)/Immigration office. But you would have to have a good reason and need to negotiate this in person, in advance.
However, if you leave the country for a reason which is not considered temporary then the residence permit would become invalid. Such reasons include:
- To work
- Attend school
- To marry and settle abroad
Example statement from Munich:
https://www.muenchen.de/rathaus/home_en/Department-of-Public-Order/Foreigners-Office/Expiry-of-residence-permit.html
Therefore, while a period of a few months working on a project in Sweden might be acceptable if seconded by your employer, a period of 2 years is too long.
You could apply for a Blue Card for Sweden, although the exact conditions may vary compared to Germany. Although this is a new application and your cannot "transfer" your blue card from Germany, the fact that you had a Blue card in Germany would normally be seen as favourable.