Lewati ke konten utama

Table.ReplaceValue

Mengganti satu nilai dengan nilai lain pada kolom tertentu.

Syntax

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

Remarks

Mengganti nilai dengan nilai baru dalam kolom tabel yang ditentukan.

  • table: Tabel yang akan dicari.
  • oldValue: Nilai yang akan diganti.
  • newValue: Nilai pengganti.
  • replacer: Fungsi pengganti yang akan digunakan. Fungsi dapat berupa Replacer.ReplaceText untuk mengganti teks asli dengan teks baru, Replacer.ReplaceValue untuk mengganti nilai asli dengan nilai baru atau pengganti kustom.
  • columnsToSearch: Daftar yang berisi kolom atau kolom tertentu dalam tabel untuk mencari nilai yang akan diganti.

Examples

Example #1

Ganti teks "goodbye" dengan "world" di kolom B, yang cocok hanya dengan seluruh nilai.

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

Ganti teks "ur" dengan "or" di kolom B, yang cocok dengan semua bagian nilai.

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

Anonimkan nama karyawan AS.

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

Anonimkan semua kolom karyawan AS.

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