Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Sintaks
Table.ReplaceValue(
table as table,
oldValue as any,
newValue as any,
replacer as function,
columnsToSearch as list
) as table
Tentang
Mengganti nilai dengan nilai baru dalam kolom tabel yang ditentukan.
-
table: Tabel yang akan dicari. -
oldValue: Nilai yang akan diganti. -
newValue: Nilai penggantian. -
replacer: Fungsi pengganti yang akan digunakan. Fungsi dapat berupa Replacer.ReplaceText 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.
Contoh 1
Ganti teks "selamat tinggal" dengan "dunia" di kolom B, yang hanya cocok dengan seluruh nilai.
Penggunaan
Table.ReplaceValue(
Table.FromRecords({
[A = 1, B = "hello"],
[A = 2, B = "goodbye"],
[A = 3, B = "goodbyes"]
}),
"goodbye",
"world",
Replacer.ReplaceValue,
{"B"}
)
Hasil
Table.FromRecords({
[A = 1, B = "hello"],
[A = 2, B = "world"],
[A = 3, B = "goodbyes"]
})
Contoh 2
Ganti teks "ur" dengan "or" di kolom B, yang cocok dengan bagian mana pun dari nilai.
Penggunaan
Table.ReplaceValue(
Table.FromRecords({
[A = 1, B = "hello"],
[A = 2, B = "wurld"]
}),
"ur",
"or",
Replacer.ReplaceText,
{"B"}
)
Hasil
Table.FromRecords({
[A = 1, B = "hello"],
[A = 2, B = "world"]
})
Contoh 3
Menganonimkan nama karyawan AS.
Penggunaan
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"}
)
Hasil
Table.FromRecords({
[Name = "*****", Country = "US"],
[Name = "Bob", Country = "CA"]
})
Contoh 4
Anonimkan semua kolom karyawan Amerika Serikat.
Penggunaan
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"}
)
Hasil
Table.FromRecords({
[Name = "?????", Country = "??"],
[Name = "Bob", Country = "CA"]
})