You simply can not use the same bulb on 230V and 24V and get the same power. A 24V on 230V will simply blow (because it will try to, according to Ohm, draw 230V x 40W / 24V2 = 16A! or 3680W!). Other way around, a 230V bulb may lit on 24V but will nowhere output 40W. That will be closer to 0,5W...
This will be slightly different because, although a load obeys Ohms law, a incandescent will change resistance with temperature. It's a PTC. And that's the biggest point, Ohm's law works statically. Aka, you can only change a single parameter at a time. If you have a magic bulb (and it's surely not an incandescent) that works on 230VAC and 24VDC and outputs 40W on both, that still obeys Ohms law only the load isn't resistive anymore and you may not assume it to be fixed over the full voltage range ![]()