OpenBI Docs Buy

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
ParameterTypeDescription
tabletableThe table to change.
oldValueanyThe value to find; or a function of the row (each [Column]) for one that changes from row to row.
newValueanyThe value to put in; also a value or a function of the row.
replacerfunctionReplacer.ReplaceValue for whole cells, Replacer.ReplaceText for text inside a cell.
columnsToSearchlistThe columns to change.

Returns

table. The same rows and columns, with the values replaced.

Remarks

  • Replacer.ReplaceValue changes a cell only when all of it equals oldValue, exactly and with case counting: "oslo" is not "Oslo".
  • Replacer.ReplaceText changes 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"})
ProductShop
ChairOSL S
DeskOSL City

Nulls to zero

Table.ReplaceValue(#table({"Product", "Units"}, {{"Chair", null}, {"Desk", 3}}), null, 0, Replacer.ReplaceValue, {"Units"})
ProductUnits
Chair0
Desk3

Whole values, case counting

Table.ReplaceValue(#table({"Product", "Shop"}, {{"Chair", "Oslo"}, {"Desk", "oslo"}}), "Oslo", "OSL", Replacer.ReplaceValue, {"Shop"})
ProductShop
ChairOSL
Deskoslo

Replacer.ReplaceValue, Replacer.ReplaceText, Table.ReplaceErrorValues, Table.TransformColumns, Table.FillDown.

Last updated · OpenBI Studio 0.3.79