The symptom of powering off suddenly at various charge states (sometimes 25% left, sometimes 75% left) is almost always a battery that can’t keep up with the designed current. 

Some times it’s physical damage from a drop, sometimes chemical damage from being in a car trunk, sometimes just an out of spec battery. 

Any service technician with Apple diagnostics can diagnose and repair that for you. Be sure your firmware and software is up to date before paying for service, though.  

- https://apple.stackexchange.com/questions/49281/macbook-pro-randomly-shutting-down
- https://apple.stackexchange.com/questions/124839/fully-charged-macbook-air-turns-off-when-power-cord-removed

DIY repair is possible, especially if you are patient and aware an improper battery swap is a fire hazard and can afford a do over if you damage the battery when it’s out or don’t get the adhesive properly handled. 

- https://apple.stackexchange.com/a/124454/5472