Udostępnij za pośrednictwem


Table.ReplaceValue

Składnia

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

Informacje

oldValue Zamienia element na newValue w określonych kolumnach obiektu table.

Przykład 1

Zastąp tekst "goodbye" ciągiem "world" w kolumnie B, pasując tylko do całej wartości.

Użycie

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

Wyjście

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

Przykład 2

Zastąp tekst "your" ciągiem "or" w kolumnie B, pasując do dowolnej części wartości.

Użycie

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

Wyjście

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

Przykład 3

Zanonimizować nazwiska pracowników z USA.

Użycie

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

Wyjście

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

Przykład 4

Anonimizuj wszystkie kolumny pracowników w Stanach Zjednoczonych.

Użycie

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

Wyjście

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