Also, there is a small battery or capacitor on the logic board that may need to be replaced, as this has been the cause of a similar issue over many generations of Mac computer hardware. Of course there are other causes of failure, and that is why the help of an expert to troubleshoot and diagnose issues to attempt to resolve them can take time.
And it may not be resolved after the first attempt if the actual problem is deeper than first best educated guess arrived by troubleshooting. Part of some repairs requires replacement of suspect parts, even if they may not be the cause, to eliminate their being within the realm of possibility. A good read is among the original Apple Technical Service Manuals, those aren't often available to the general public. I used one to self-troublehoot an iMac under AppleCare after the nearby 200+ miles one-way distant 'specialist' could not fix my new iMac, four times. So I am a bit cool on newer Macs; the way I see it one new headache lasting 10 months and requiring 3,000 miles travel, to not be resolved by experts (and under warranty, so I can't touch it!?!) is enough.
The best cure for main power failure, is to have a good high quality battery backup system in place with automatic voltage regulation, that also works as a power filter; and can step in to isolate the Mac from mains high-or-low power fluctuation. This can save many products from bad power sources; do not rely on these, either. Make copies of your work ahead of time. This saves your computer from issues you can prevent.
PS: my Macs seldom are shut off, for up to 11 months, some of mine only get to sleep when not in use. When the main power goes offline, during a storm or extended utility failure of their own making, I will have to shut them off as a choice. There is software in the UPS unit that can help shut down automatically, and that is a choice, too. I usually find their software problematic on occasion; and the battery backup is not very long in duration, so one with a few hours runtime and a method of rationing the power if you are present when the mains fail, is helpful in performing a normal shutdown after a power failure.
Good luck & happy computing! 🙂