メインコンテンツまでスキップ

Table.ReplaceValue

指定された列で値を別の値に置き換えます。

Syntax

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

Remarks

table の指定された列で oldValuenewValue に置き換えます。

Examples

Example #1

列 B のテキスト "goodbye" を "world" に置き換え、値全体だけを一致させます。

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

列 B のテキスト "ur" を "or" に置き換え、値の任意の部分に一致させます。

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

米国の従業員の名前を匿名化します。

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

米国の従業員のすべての列を匿名化します。

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