OpenBI Docs Buy

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
ParameterTypeDescription
listlistThe list.
oldValueanyThe value to find.
newValueanyWhat to put instead.
replacerfunctionReplacer.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"}

Replacer.ReplaceValue, Replacer.ReplaceText, Table.ReplaceValue.

Last updated · OpenBI Studio 0.3.79