
Energy Question (M) made a variety of information transformation actions a lot simpler and worth alternative is considered one of them. You may simply proper click on on any desired worth in Energy Question, both in Excel or Energy BI, or different elements of Energy Platform basically, and easily change that worth with any desired different. Changing values primarily based on sure situations nevertheless, might not appear that simple at first. I’ve seen a variety of Energy Question (M) builders including new columns to perform that. However including a brand new column shouldn’t be at all times a good suggestion, particularly when you are able to do it in a easy single step in Energy Question. On this publish I present you a fast and straightforward option to that may allow you to dealing with many alternative worth alternative situations.
Think about you may have a desk like under and you’ve got a requirement to exchange the values column [B] with the values of column [C] if the [A] = [B].

A method is so as to add a brand new conditional column and with the next logic:
if [B] = [A] then [C] else [B]

Properly, it really works completely advantageous, however wait, you’re including a brand new column proper? Wouldn’t it’s higher to deal with the above easy state of affairs with out including a brand new column? In case your reply is sure then proceed studying.
You should utilize the Question Editor UI to assemble the worth alternative in Energy Question to keep away from misspelling, case sensitivity points, and so forth… and truthfully, it’s easier to make use of the UI when attainable than typing lengthy M codes. In any case… Let’s take away the brand new column we created beforehand and undergo the second state of affairs.
Proper click on on a price in column B and click on “Substitute Values”

Substitute the chosen worth with any desired worth. In my instance I changed 5 with 1000.

All it’s worthwhile to do now’s to change the code with the right logic. Let’s evaluation the logic, we wish to test for every worth of column [B] in each single uncooked of the desk and change it with a price of column [C] provided that [B] = [A].
I highlighted the “every” because it is a crucial key phrase in Energy Question.
So we solely want to change the Energy Question code as under:
- change “5” with every [A]
- change “1000” with every [C]
So the ultimate code could be:
=Desk.ReplaceValue(Supply, every [A], every [C],Replacer.ReplaceText,{"B"})

The above code finds worth of column [A] in [B], in the event that they’re equal then replaces the worth of column [B] with the worth of column [C].
To learn extra about how one can reference in Energy Question take a look at my earlier publish right here.