MS was basically making money no matter what given the highly lucrative office + windows franchise that Bill Gates left behind. I wouldn't credit Balmer with that too much he just basically kept on milking that. The problem by the time he left was that there was increasingly less to squeeze.
Shareholders tend to look forward rather than backward and it was getting very clear that windows and office were increasingly less critical to users and that there were some serious revenue issues around that going forward. Windows on the server was basically getting less relevant by the day. Windows desktop was feeling a lot of pressure from Apple and increasingly Google. Office sales were suffering when companies started using alternative office tools from e.g. Google. Windows Phone was not working that great either and struggled to gain market share on Apple and Google. The Nokia acquisition that Balmer pushed through was sort of the nail in the coffin here. That was an expensive failure and that is 100% on Balmer.
The keyword in those strategies was windows. Under Balmer it absolutely had to be windows everywhere. Server, desktop, mobile, IOT, and all the rest. It wasn't working. That's why Balmer 'left' (i.e. was pretty much fired but in a nice face saving way).
Nadella killed that windows everything strategy and turned things around. Office is now liberated from Windows and making a lot of money for MS again. Cloud is growing more important as well, courtesy of mostly non windows software running on Linux in Azure. Meanwhile windows on the desktop seems pretty cool now that MS has added Linux integration, a non MS browser, and a few other things that make it a lot more attractive for developers and users and now that they are no longer forced to be in this windows everything walled garden. Even mobile is doing great for MS now that they can focus on treating IOS and Android as first class citizens.