iMac random shutdown
I can't imagine the Apple Store haven't already done this - but have you/they tried resetting the SMC?

For iMacs, the steps to do this are:


Shut down your computer
Unplug it from the power socket 
Press and hold the power button for 5 seconds
Plug it back in and turn it on.


However, assuming they have already tried this, there are other things they can do, such as swapping over the logic board.

Troubleshooting is a process of elimination, and you know that reinstalling macOS doesn't resolve the issue, and neither does replacing the RAM. So, if it was me, the logic board would be next.

Let us know how you go.