Mayer, as always, is on point.
With the system booted, try following these directions: https://support.apple.com/en-us/HT201585
That should provide some detail to let you know if this is a battery issue, which is most likely.
Also... much like the battery and alternator relationship in a car.... remove the batter and boot with just the power cable. If it works... and booting with the battery alone doesn't, it's likely the battery. Though, you're having intermittent issues, so I'm not sure if you would be able to get definite results.