A method for controlling a vehicle with a drive system comprising a power assembly configuration configured to provide power for the propulsion of the vehicle, a planetary gearing comprising three components in the form of a sun gear, a ring gear and a planetary gears carrier, an input shaft of the planetary gearing being connected to a first of said components of the planetary gearing so that a rotation of this shaft results in a rotation of this component, an output shaft of the planetary gearing constituting an input shaft of a gearbox for transmitting a torque for the propulsion of the vehicle being connected to a second of said components of the planetary gearing so that a rotation of this output shaft results in a rotation of this component, said power assembly configuration comprises a first electric machine with a stator and a rotor connected to a third of said components of the planetary gearing so that rotation of the rotor results in a rotation of this component and a combustion engine with an output shaft connected to said input shaft of the planetary gearing, said drive system further comprising a first locking means transferable between a locking position in which two of said components are interlocked so that said three components rotate with the same rotation speed and a releasing position in which said components are allowed to rotate with different rotation speeds, characterized in that said control is carried out for a vehicle having a said power assembly configuration which also comprises a second electric machine with a stator and a rotor connected to the input shaft of the planetary gearing, and that the method comprises the following steps for carrying out shifting from a present gear to a new gear in the gearbox when driving the vehicle with said first locking means in said locking position: a) controlling the power assembly configuration to decrease the torque applied on said input shaft of the gearbox to decrease towards zero and to obtain torque balance in the planetary gearing, b) upon obtaining torque balance in the planetary gearing, transferring said first locking means to said releasing position and starting to control members of the power assembly configuration acting upon said first component towards a target rotation speed of said new gear to be shifted to, c) disengaging said present gear of the gearbox when the torque on said input shaft of the gearbox reaches zero and starting to control said power assembly configuration to apply a torque to said input shaft being negative when said new gear is higher than said present gear and positive when said new gear is lower than said present gear for controlling the rotation speed of said input shaft of the gearbox towards said target rotation speed of said new gear, d) when the rotation speed of said input shaft of the gearbox reaches said target rotation speed, engaging said new gear, controlling the power assembly configuration to increase the torque on said input shaft of the gearbox while maintaining torque balance in the planetary gearing and continuing to control members of the power assembly configuration acting upon said first component towards said target rotation speed, and e) upon obtaining said target rotation speed of the input shaft of the planetary gearing transferring said first locking means to the locking position and continuing to control the power assembly configuration to increase the torque applied on said input shaft of the gearbox while controlling the different members of the power assembly configuration to deliver torques of desired values. a) controlling the power assembly configuration to decrease the torque applied on said input shaft of the gearbox to decrease towards zero and to obtain torque balance in the planetary gearing, b) upon obtaining torque balance in the planetary gearing, transferring said first locking means to said releasing position and starting to control members of the power assembly configuration acting upon said first component towards a target rotation speed of said new gear to be shifted to, c) disengaging said present gear of the gearbox when the torque on said input shaft of the gearbox reaches zero and starting to control said power assembly configuration to apply a torque to said input shaft being negative when said new gear is higher than said present gear and positive when said new gear is lower than said present gear for controlling the rotation speed of said input shaft of the gearbox towards said target rotation speed of said new gear, d) when the rotation speed of said input shaft of the gearbox reaches said target rotation speed, engaging said new gear, controlling the power assembly configuration to increase the torque on said input shaft of the gearbox while maintaining torque balance in the planetary gearing and continuing to control members of the power assembly configuration acting upon said first component towards said target rotation speed, and e) upon obtaining said target rotation speed of the input shaft of the planetary gearing transferring said first locking means to the locking position and continuing to control the power assembly configuration to increase the torque applied on said input shaft of the gearbox while controlling the different members of the power assembly configuration to deliver torques of desired values.