Table.ReplaceValue

Sözdizimi

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

Hakkında

oldValue öğesinin belirtilen sütunlarında tableile newValue değiştirir.

Örnek 1

"Goodbye" metnini B sütunundaki "world" ile değiştirerek yalnızca değerin tamamını eşleştirin.

Kullanım

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

Çıkış

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

Örnek 2

"your" metnini B sütunundaki "veya" ile değiştirerek değerin herhangi bir bölümünü eşleştirin.

Kullanım

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

Çıkış

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

Örnek 3

ABD çalışanlarının adlarını anonimleştirin.

Kullanım

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

Çıkış

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

Örnek 4

ABD çalışanlarının tüm sütunlarını anonimleştirin.

Kullanım

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

Çıkış

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