Jaa


Table.ReplaceValue

Syntaksi

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

Tietoja

Korvaa oldValue kohteen kohteella newValue kohteen määritetyissä sarakkeissa table.

Esimerkki 1

Korvaa teksti "goodbye" tekstillä "world" sarakkeessa B vertaamalla vain koko arvoa.

Käyttö

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

Tuloste

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

Esimerkki 2

Korvaa teksti "your" tekstillä "or" sarakkeessa B täsmääen arvon minkä tahansa osan.

Käyttö

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

Tuloste

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

Esimerkki 3

Anonymisoida yhdysvaltojen työntekijöiden nimet.

Käyttö

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

Tuloste

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

Esimerkki 4

Anonymisoida kaikki yhdysvaltalaisen työntekijän sarakkeet.

Käyttö

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

Tuloste

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