Inclusion Criteria:  Female of non-childbearing potential or male Age above or equal to 18 years at the time of signing informed consent Body mass index (BMI) greater than or equal to 27.0 kg/m^2 Diagnosed with type 2 diabetes mellitus greater than or equal to 180 days before screening Glycated haemoglobin (HbA1c) of 7.5-10.0% (58-86 mmol/mol) (both inclusive) as assessed by central laboratory at screening Stable daily dose(s) ≥ 90 days before screening of the following antidiabetic drug(s) or combination regimen(s) at maximum tolerated or effective dose as judged by the investigator: metformin with or without Sodium-glucose co-transporter-2 (SGLT2) inhibitor  Exclusion Criteria:  Treatment with any medication for the indication of diabetes or obesity other than stated in the inclusion criteria within 90 days before screening. However, short term insulin treatment for a maximum of 14 days and prior insulin treatment for gestational diabetes are allowed Renal impairment with estimated Glomerular Filtration Rate (eGFR) below 60 ml/min/1.73m^2 by central laboratory at screening Uncontrolled and potentially unstable diabetic retinopathy or maculopathy. Verified by a fundus examination performed within 90 days before screening or in the period between screening and randomisation. Pharmacological pupil-dilation is a requirement unless using a digital fundus photography camera specified for non-dilated examination