The rear section of the sunroof will not close.
What does it do when you try to close it?
If it begins to close then reverses and reopens, you likely have excess friction in the tracks and the “child safe” system is detecting what it interprets as an obstuction and reversing the system. That may necessitate cleaning and lubing the tracks.
If it does absolutely nothing, you’ll need to see if you have poower at the motor when the botton is pressed. That may take removal of the inner liner panels and possibly even the sunroof assembly. The dealer should be able to print an “exploded view” drawing of how the assembly is installed for you.
“Panoramic sunroof 2004 BMW X3”
This repair may require a panoramic wallet…
I cant picture what a rear section would be but are you talking about the piece that is colored the same as the headliner?
Sunroof repair is a teach yourself endeavour, there is no school, Sunroof repair can quickly turn into a complete sunroof cassette replacement if you are not careful. Have it looked at by someone with experience.