Add Values to Column
Add Values to Same Column
Abstract
I sometimes want to add values to an existing column without adding a new column. Here is how to do it in one line of M code
Setup:
We can insert this step by selecting power query menu option Home > Replace Values (in the Transform group) and then modifying the code as shown below. Alternatively, we can insert this line in the Advanced Editor.
Syntax:
Below is the syntax for the statement.
= Table.ReplaceValue(<PreviousStep>,
each [<CurrentColumn>],
each [<CurrentColumn>] + [<OtherColumn>],
Replacer.ReplaceValue,{"<CurrentColumn>"})
Where:
<PreviousStep> Is the name of the previous step in the query we are building
<CurrentColumn> Is the name of the column we will be changing
<OtherColumn> Is the name, or names of columns containing values we want to add, or the literal value to add.
Notes:
The code above adds numeric values. We can perform any computation we like.
To perform text manupulation we must change Replacer.ReplaceValue to Replacer.ReplaceText.