Table.SplitColumn
Opdeler den angivne kolonne i et sæt ekstra kolonner ved hjælp af den angivne opdelingsfunktion.
Syntax
Table.SplitColumn(
table as table,
sourceColumn as text,
splitter as function,
optional columnNamesOrNumber as any,
optional default as any,
optional extraColumns as any
) as table
Remarks
Splits the specified column into a set of additional columns using the specified splitter function.
table: The table containing the column to split.sourceColumn: The name of the column to split.splitter: The splitter function used to split the column (for example,Splitter.SplitTextByDelimiterorSplitter.SplitTextByPosition).columnNamesOrNumber: Either a list of new column names to create, or the number of new columns.default: Overrides the value used when there aren't enough split values to fill all of the new columns. The default for this parameter isnull.extraColumns: Specifies what to do if there might be more split values than the number of new columns. You can pass anExtraValues.Typeenumeration value to this parameter. The default isExtraValues.Ignore.
Examples
Example #1
Opdel navnekolonnen i fornavn og efternavn.
let
Source = #table(type table[CustomerID = number, Name = text, Phone = text],
{
{1, "Bob White", "123-4567"},
{2, "Jim Smith", "987-6543"},
{3, "Paul", "543-7890"},
{4, "Cristina Best", "232-1550"}
}),
SplitColumns = Table.SplitColumn(
Source,
"Name",
Splitter.SplitTextByDelimiter(" "))
in
SplitColumns
Result:
#table(type table[CustomerID = number, Name.1 = text, Name.2 = text, Phone = text],
{
{1, "Bob", "White", "123-4567"},
{2, "Jim", "Smith", "987-6543"},
{3, "Paul", null, "543-7890"},
{4, "Cristina", "Best", "232-1550"}
})
Example #2
Opdel navnekolonnen i fornavn og efternavn, og omdøb derefter de nye kolonner.
let
Source = #table(type table[CustomerID = number, Name = text, Phone = text],
{
{1, "Bob White", "123-4567"},
{2, "Jim Smith", "987-6543"},
{3, "Paul", "543-7890"},
{4, "Cristina Best", "232-1550"}
}),
SplitColumns = Table.SplitColumn(
Source,
"Name",
Splitter.SplitTextByDelimiter(" "),
{"First Name", "Last Name"})
in
SplitColumns
Result:
#table(type table[CustomerID = number, First Name = text, Last Name = text, Phone = text],
{
{1, "Bob", "White", "123-4567"},
{2, "Jim", "Smith", "987-6543"},
{3, "Paul", null, "543-7890"},
{4, "Cristina", "Best", "232-1550"}
})
Example #3
Opdel navnekolonnen i fornavn og efternavn, omdøb de nye kolonner, og udfyld eventuelle tomme kolonner med "-No Entry-".
let
Source = #table(type table[CustomerID = number, Name = text, Phone = text],
{
{1, "Bob White", "123-4567"},
{2, "Jim Smith", "987-6543"},
{3, "Paul", "543-7890"},
{4, "Cristina Best", "232-1550"}
}),
SplitColumns = Table.SplitColumn(
Source,
"Name",
Splitter.SplitTextByDelimiter(" "),
{"First Name", "Last Name"},
"-No Entry-")
in
SplitColumns
Result:
#table(type table[CustomerID = number, First Name = text, Last Name = text, Phone = text],
{
{1, "Bob", "White", "123-4567"},
{2, "Jim", "Smith", "987-6543"},
{3, "Paul", "-No Entry-", "543-7890"},
{4, "Cristina", "Best", "232-1550"}
})
Example #4
Opdel navnekolonnen i fornavn og efternavn, og omdøb derefter de nye kolonner. Da der kan være flere værdier end antallet af tilgængelige kolonner, skal du gøre kolonnen med efternavnet til en liste, der indeholder alle værdier efter fornavnet.
let
Source = #table(type table[CustomerID = number, Name = text, Phone = text],
{
{1, "Bob White", "123-4567"},
{2, "Jim Smith", "987-6543"},
{3, "Paul Green", "543-7890"},
{4, "Cristina J. Best", "232-1550"}
}),
SplitColumns = Table.SplitColumn(
Source,
"Name",
Splitter.SplitTextByDelimiter(" "),
{"First Name", "Last Name"},
null,
ExtraValues.List)
in
SplitColumns
Result:
#table(type table[CustomerID = number, First Name = text, Last Name = text, Phone = text],
{
{1, "Bob", {"White"}, "123-4567"},
{2, "Jim", {"Smith"}, "987-6543"},
{3, "Paul", {"Green"}, "543-7890"},
{4, "Cristina", {"J.", "Best"}, "232-1550"}
})
Category
Table.Transformation