Delen via


Table.ReplaceValue

Syntaxis

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

Info

oldValue Vervangt door newValue in de opgegeven kolommen van de table.

Voorbeeld 1

Vervang de tekst 'afscheid' door 'wereld' in kolom B, die alleen overeenkomt met de volledige waarde.

Gebruik

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

Uitvoer

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

Voorbeeld 2

Vervang de tekst 'your' door 'or' in kolom B, die overeenkomt met een deel van de waarde.

Gebruik

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

Uitvoer

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

Voorbeeld 3

De namen van amerikaanse werknemers anoniem maken.

Gebruik

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

Uitvoer

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

Voorbeeld 4

Alle kolommen van Amerikaanse werknemers anoniem maken.

Gebruik

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

Uitvoer

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