Table.SplitColumn
使用指定的拆分器函数将指定的列拆分为一组其他列。
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
使用指定的拆分器函数将指定的列拆分为一组其他列。
table: 包含要拆分的列的表。sourceColumn: 要拆分的列的名称。splitter: 用于拆分列的拆分器函数(例如,Splitter.SplitTextByDelimiter或Splitter.SplitTextByPosition)。columnNamesOrNumber: 要创建的新列名列表或新列数。default: 替代当没有足够的拆分值来填充所有新列时使用的值。此参数的默认值为null。extraColumns: 指定如果拆分值的数量可能多于新列的数量时该怎么做。可以将ExtraValues.Type枚举值传递给此参数。默认值为ExtraValues.Ignore。
Examples
Example #1
将姓名列拆分为名字和姓氏。
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
将姓名列拆分为名字和姓氏,然后重命名新列。
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
将姓名列拆分为名字和姓氏,重命名新列,并使用 "-无条目-" 填充任何空白。
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
将姓名列拆分为名字和姓氏,然后重命名新列。由于值的数量可能多于可用列的数量,因此请将姓氏列设为包含名字后所有值的列表。
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