Ga naar hoofdinhoud

Table.ReplaceValue

Vervangt de ene waarde door een andere waarde in de opgegeven kolommen.

Syntax

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

Remarks

Vervangt oldValue door newValue in de opgegeven kolommen van de table.

Examples

Example #1

Vervang de tekst 'tot ziens' door 'wereld' in kolom B, waarbij alleen de hele waarde overeenkomt.

Table.ReplaceValue(
Table.FromRecords({
[A = 1, B = "hello"],
[A = 2, B = "goodbye"],
[A = 3, B = "goodbyes"]
}),
"goodbye",
"world",
Replacer.ReplaceValue,
{"B"}
)

Result:

Table.FromRecords({
[A = 1, B = "hello"],
[A = 2, B = "world"],
[A = 3, B = "goodbyes"]
})

Example #2

Vervang de tekst 'uw' door 'of' in kolom B, waarbij een gedeelte van de waarde overeenkomt.

Table.ReplaceValue(
Table.FromRecords({
[A = 1, B = "hello"],
[A = 2, B = "wurld"]
}),
"ur",
"or",
Replacer.ReplaceText,
{"B"}
)

Result:

Table.FromRecords({
[A = 1, B = "hello"],
[A = 2, B = "world"]
})

Example #3

De namen van Amerikaanse werknemers anoniem maken.

Table.ReplaceValue(
Table.FromRecords({
[Name = "Cindy", Country = "US"],
[Name = "Bob", Country = "CA"]
}),
each if [Country] = "US" then [Name] else false,
each Text.Repeat("*", Text.Length([Name])),
Replacer.ReplaceValue,
{"Name"}
)

Result:

Table.FromRecords({
[Name = "*****", Country = "US"],
[Name = "Bob", Country = "CA"]
})

Example #4

Alle kolommen van Amerikaanse werknemers anoniem maken.

Table.ReplaceValue(
Table.FromRecords({
[Name = "Cindy", Country = "US"],
[Name = "Bob", Country = "CA"]
}),
each [Country] = "US",
"?",
(currentValue, isUS, replacementValue) =>
if isUS then
Text.Repeat(replacementValue, Text.Length(currentValue))
else
currentValue,
{"Name", "Country"}
)

Result:

Table.FromRecords({
[Name = "?????", Country = "??"],
[Name = "Bob", Country = "CA"]
})

Category

Table.Transformation