I did what you're describing and it worked out well for me, but YMMV. Here's what I did:
I got an undergrad degree in physics, and was hired right out of school by a government contractor. My only hard skill from the degree was coding in LabVIEW, something I never have done in the workplace. Arguably my only real use in my first job was to be a person who submitted a timesheet that could be billed as a person with a STEM degree.
I changed jobs for a much better contractor where I did a lot of "system engineering" style analysis with MatLab, which I mostly learned on the job, and eventually moved into Python which I learned entirely on the job. Python really resonated with me, particularly using it for Data Science applications. I got a Masters degree in Applied Physics from a highly renowned school taking after hours courses that my job paid for. Most of the courses had no conceivable application to my day job.
I eventually was hired away from the contracting world and am a Data Engineer for a private company.
The thing a physics degree truly demonstrates is the ability to learn difficult concepts, think analytically, and have the math to back it up. If you go this route, you'll kind of be a generalist right out of the gate and need to be open to trying a bunch of new things to figure out what works for you. A master's degree certainly helps, and learning a useful programming language really helps. Be prepared to start somewhere as an analyst, and build from there.