Zdieľať cez


Table.ReplaceValue

Syntax

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

Informácie

oldValue Nahradí hodnotu za newValue v zadaných stĺpcoch tabuľky table.

Príklad č. 1

Nahraďte text "goodbye" textom "world" v stĺpci B, ktorý zodpovedá len celej hodnote.

Použitie

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

Výkon

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

Príklad č. 2

Nahraďte text "your" textom "or" v stĺpci B, ktorý zodpovedá ľubovoľnej časti hodnoty.

Použitie

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

Výkon

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

Príklad č. 3

Anonymizovanie mien zamestnancov USA.

Použitie

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

Výkon

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

Príklad č. 4

Anonymizovanie všetkých stĺpcov zamestnancov USA.

Použitie

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

Výkon

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

Funkcie nahrádzača