Back in 2022 I wrote a post detailing the various ways you can replace part of a string in M code (Power Query). It's actually the post I refer back to the most, but I've recently come across a couple of related posts so thought I would quickly add them here.
Replace values in a column using if statements
I adapted this one from this thread in the Fabric Forum. In the original example I was trying to remove the same string from any appearance of it in a field in a column, but what about if your problem is the other way around – i.e. the part you want to keep is always the same, but the part you want to lose varies, in unknowable ways.
In this case you can use an if function in the middle of the command like this:
= Table.ReplaceValue(#"Previous Step Name", each [Column1],each
if Text.Start([Column1]), 7) = "My term" then "My new term" else [Column1],
Replacer.ReplaceValue,{"Column1"})
Replace/Swap multiple values for another value at once
If you want to replace the entire contents of a cell with another value (by specifying the whole contents in both cases) then you can do use this:
= List.Accumulate({{"YYY", "yyyyy"}, {"XXX", "XXXXX"}},
#"Expanded Table Column", (state, current) => Table.ReplaceValue(state, current{0}, current{1}, Replacer.ReplaceValue, {"Team"}))