the first thing to do will be reset the transmission. Turn the ignition all the way on with engine off, then press the accelerator pedal to the floor for 2min. see if that helps.
if that does not help, the next step will be to have the transmission fluid level and condition checked. Low fluid can cause bizarre behavior as it is then able to slosh around inside the transmission. If the fluid is burnt/dark/dirty, then this would reveal an internal wear/mechanical issue.
if the issue still exists, then the next step would be a software check / reload at a BMW main dealer or specilalist.
if again the issue persists, then there is likely an internal mechanical fault which will require transmission rebuild or replacement. it may be possible to trace the issue to a single component through detailed diagnostics, but usually if the transmission needs to be opened for repair it makes sense to invest in a rebuild
Sorry if you were hoping for a different answer, please don't shoot the messenger - I can only give the honest answer, which I have. Please remember that a low rating PUNISHES me for my honest and prompt response, and I receive nothing for my time and answer until a positive rating is clicked.Please let me know if you have further questions. Please do not forget to click a positive rating as this is the only way I receive credit for my answer, thank you. Best wishes with your vehicle.