It needs to be set before the engine starts, i.e. either through command line parameters or default engine files. Once set in the default engine, you need to restart the game for it to work correctly.
However, in 4.27 it is bugged and doesn’t work, which is pretty major.
This will work if placed in BaseEngine.ini (in your Engine/Config folder). This will make the change global for all projects opened in that Engine version on that PC.
You can put it in WindowsEngine.ini and it will only affect instances of the Editor opened on Windows PC’s.
You can alternatively put it in DefaultEngine.ini (in your Project/Config folder) to make it stick only to that project.
NOTE: In my tests, trying to switch GPU’s when they have SLI/NVLink enabled will technically work, but you’ll get warnings that your hardware doesn’t support DX12/SM6, so it actually doesn’t work.
I found old threads about this subject with varying degrees of success and relevancy. You cannot set this variable in console cmdline arguments (e.g. UnrealEditor.exe -ExecCmds="..."), it is read-only once the engine starts.
For completeness, the files are
Project/Config/DefaultEngine.ini or Engine/Config/BaseEngine.ini