Bagikan melalui


Table.ReplaceValue

Sintaks

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

Tentang

oldValue Mengganti dengan newValue dalam kolom yang ditentukan dari table.

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 "Anda" dengan "atau" 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 AS.

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"]
})

Fungsi pengganti