Table.ReplaceMatchingRows

Table

Replaces rows that match specified records with new values.

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

Syntax

Table.ReplaceMatchingRows(table as table, rows as list, optional equationCriteria as any) as table

Parameters

NameTypeRequiredDescription
tabletableYesThe table to update.
rowslistYesA list of {oldRow, newRow} pairs, where each pair is a two-element list: the record to match and the record to replace it with.
equationCriteriaanyNoOptional. Column name(s) or comparer to restrict matching to specific fields.

Return Value

tableThe table with matching rows replaced by their corresponding replacement records.

Remarks

Table.ReplaceMatchingRows accepts a list of {oldRecord, newRecord} pairs. For each pair, any table row that matches oldRecord is replaced with newRecord. All matching rows are replaced, not just the first occurrence.

This function operates on whole rows. To replace values within individual cells, use Table.ReplaceValue.

Examples

Example 1: Replace a matching row

Table.ReplaceMatchingRows(
    #table({"ID", "Status"}, {{1, "Pending"}, {2, "Done"}, {3, "Pending"}}),
    {
        {[ID = 1, Status = "Pending"], [ID = 1, Status = "Approved"]}
    }
)
Result
ID
Status
11Approved
22Done
33Pending

Example 2: Replace multiple rows

Table.ReplaceMatchingRows(
    #table({"Code"}, {{"A"}, {"B"}, {"C"}}),
    {
        {[Code = "A"], [Code = "Alpha"]},
        {[Code = "C"], [Code = "Charlie"]}
    }
)
Result
Code
1Alpha
2B
3Charlie

Compatibility

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