Table.ReplaceValue

Table

Replaces occurrences of a value in specified columns using a replacer function.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Table.ReplaceValue(table as table, oldValue as any, newValue as any, replacer as function, columnsToSearch as list) as table

Parameters

NameTypeRequiredDescription
tabletableYesThe input table containing values to replace.
oldValueanyYesThe value to search for.
newValueanyYesThe replacement value.
replacerfunctionYesThe replacer function: Replacer.ReplaceValue for exact match, or Replacer.ReplaceText for substring replacement.
columnsToSearchlistYesA list of column names in which to perform the replacement.

Return Value

tableThe input table with the specified values replaced.

Remarks

Table.ReplaceValue searches for oldValue in the specified columns and replaces it with newValue. The replacer parameter determines the matching behavior:

- Replacer.ReplaceValue — performs an exact match on the entire cell value. Use this for replacing nulls, numbers, or exact text matches. - Replacer.ReplaceText — performs a substring replacement within text values. Use this for find-and-replace operations within strings.

If you have multiple replace operations on the same column, consider consolidating them into a single Table.TransformColumns call with a translation table or conditional logic. Multiple separate Table.ReplaceValue steps add unnecessary overhead.

Examples

Example 1: Replace exact values

Table.SelectColumns(
    Table.ReplaceValue(Sales, "East", "Eastern", Replacer.ReplaceValue, {"Region"}),
    {"CustomerName", "Product", "Region"}
)
Result
CustomerName
Product
Region
1AliceWidget AEastern
2BobGadget BWest
3CharlieWidget CEastern
4AliceGadget DNorth
5DianaWidget AWest
6BobThingamajig EEastern
7CharlieGadget BWest
8DianaWidget CNorth

Example 2: Replace null values

let
    WithNull = Table.ReplaceValue(
        Table.SelectColumns(Table.FirstN(Sales, 4), {"CustomerName", "Region"}),
        "North", null, Replacer.ReplaceValue, {"Region"}
    )
in
    Table.ReplaceValue(WithNull, null, "Unknown", Replacer.ReplaceValue, {"Region"})
Result
CustomerName
Region
1AliceEast
2BobWest
3CharlieEast
4AliceUnknown

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks