List.ReplaceValue
A list with a value replaced, by a replacer that says how.
Group: List. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
List.ReplaceValue(list as list, oldValue as any, newValue as any, replacer as function) as list
| Parameter | Type | Description |
|---|---|---|
list | list | The list. |
oldValue | any | The value to find. |
newValue | any | What to put instead. |
replacer | function | Replacer.ReplaceValue for whole items, Replacer.ReplaceText for a piece of text inside each item. |
Returns
list. As many items as the list, with the replacements made.
Examples
Zeros to null
List.ReplaceValue({120, 0, 85, 0}, 0, null, Replacer.ReplaceValue)
{120, null, 85, null}
Whole items only
List.ReplaceValue({"pcs", "pcs.", "kg"}, "pcs", "piece", Replacer.ReplaceValue)
{"piece", "pcs.", "kg"}
Inside the text
List.ReplaceValue({"pcs", "pcs.", "kg"}, "pcs", "piece", Replacer.ReplaceText)
{"piece", "piece.", "kg"}
Related functions
Replacer.ReplaceValue, Replacer.ReplaceText, Table.ReplaceValue.