Table.ReplaceValue
Finds a value, or a piece of text, in the columns you name and puts another in its place.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.ReplaceValue(table as table, oldValue as any, newValue as any, replacer as function, columnsToSearch as list) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table to change. |
oldValue | any | The value to find; or a function of the row (each [Column]) for one that changes from row to row. |
newValue | any | The value to put in; also a value or a function of the row. |
replacer | function | Replacer.ReplaceValue for whole cells, Replacer.ReplaceText for text inside a cell. |
columnsToSearch | list | The columns to change. |
Returns
table. The same rows and columns, with the values replaced.
Remarks
Replacer.ReplaceValuechanges a cell only when all of it equals oldValue, exactly and with case counting: "oslo" is not "Oslo".Replacer.ReplaceTextchanges every place the text occurs inside a cell.- Replace Values in Transform data writes this step; to fill empty cells, replace null with
Replacer.ReplaceValue.
Examples
Text inside the cells
Table.ReplaceValue(
#table({"Product", "Shop"}, {{"Chair", "Oslo S"}, {"Desk", "Oslo City"}}),
"Oslo", "OSL", Replacer.ReplaceText, {"Shop"})
| Product | Shop |
|---|---|
| Chair | OSL S |
| Desk | OSL City |
Nulls to zero
Table.ReplaceValue(#table({"Product", "Units"}, {{"Chair", null}, {"Desk", 3}}), null, 0, Replacer.ReplaceValue, {"Units"})
| Product | Units |
|---|---|
| Chair | 0 |
| Desk | 3 |
Whole values, case counting
Table.ReplaceValue(#table({"Product", "Shop"}, {{"Chair", "Oslo"}, {"Desk", "oslo"}}), "Oslo", "OSL", Replacer.ReplaceValue, {"Shop"})
| Product | Shop |
|---|---|
| Chair | OSL |
| Desk | oslo |
Related functions
Replacer.ReplaceValue, Replacer.ReplaceText, Table.ReplaceErrorValues, Table.TransformColumns, Table.FillDown.