You choose the mode as the triggered ability goes on the stack. You can choose a mode that requires targets only if there are legal targets available.

Artwork
Loading artwork…
Gandalf the Grey
The Lord of the Rings: Tales of Middle-earth · #207 · EN
Nonfoil—Foil—
Card rules
Whenever you cast an instant or sorcery spell, choose one that hasn't been chosen —
• You may tap or untap target permanent.
• Gandalf deals 3 damage to each opponent.
• Copy target instant or sorcery spell you control. You may choose new targets for the copy.
• Put Gandalf on top of its owner's library.
3/4
Rare · Illustrated by Aaron Miller
Format legality
Brawl Legal
Commander Legal
Competitive Brawl Legal
Duel Legal
Gladiator Legal
Historic Legal
Legacy Legal
Modern Legal
Oathbreaker Legal
Penny Legal
Timeless Legal
Vintage Legal
Alchemy Not Legal
Future Not Legal
Old School Not Legal
Pauper Not Legal
Pauper Commander Not Legal
Pioneer Not Legal
PreDH Not Legal
Premodern Not Legal
Standard Not Legal
Standard Brawl Not Legal
Tlr Not Legal
Rulings
Published rulings from the downloaded Scryfall catalog. Source card record · Rules and interactions
It doesn't matter who has chosen any particular mode. For example, say you control Gandalf the Grey and have chosen the first two modes. If an opponent gains control of Gandalf the Grey, that player can choose only the third or fourth mode.
If the ability doesn't resolve (either for having its target become illegal or because a spell or ability counters it), the mode chosen for that instance of the ability still counts as being chosen.
The phrase "that hasn't been chosen" refers only to that specific Gandalf the Grey. If Gandalf the Grey leaves the battlefield (possibly because of the fourth mode of its ability) and then returns to the battlefield later, it will be a new object with no memory of the modes chosen when it was last on the battlefield.