Jaa kautta


Table.ReplaceValue

Syntaksi

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

Tietoja

Korvaa arvon uudella arvolla taulukon määritetyissä sarakkeissa.

  • table: Haettava taulukko.
  • oldValue: Korvattava arvo.
  • newValue: Jälleenhankinta-arvo.
  • replacer: Käytettävä korvaava toiminto. Toiminto voi olla joko Replacer.ReplaceText alkuperäisen tekstin korvaaminen uudella tekstillä, Replacer.ReplaceValue alkuperäisen arvon korvaaminen uudella arvolla tai mukautettu korvaaja.
  • columnsToSearch: Luettelo, joka sisältää taulukon tietyn sarakkeen tai sarakkeet korvattavan arvon etsimistä varten.

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

Korvaustoimintofunktiot