|
方法1
let
Source = Excel.CurrentWorkbook(){[Name = "表1"]}[Content],
AddIndex = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
Grouped = Table.Group(
AddIndex,
"户号",
{{"所有记录", each _, type table [户号 = Int64.Type, 姓名 = nullable text, Index = Int64.Type]}}
),
// Create a table which ensures that every group has at least 4 rows
EnsureRows = Table.TransformColumns(
Grouped,
{
"所有记录",
each
if Table.RowCount(_) >= 4 then
_
else
Table.Combine(
{_, Table.FromRecords(List.Repeat({[姓名 = null, Index = null]}, 4 - Table.RowCount(_)))}
),
type table [户号 = Int64.Type, 姓名 = nullable text, Index = Int64.Type]
}
),
Expanded = Table.ExpandTableColumn(EnsureRows, "所有记录", {"户号1", "姓名", "Index"})
in
Expanded
方法2
let
Source = Excel.CurrentWorkbook(){[Name = "表1"]}[Content],
AddIndex = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
Grouped = Table.Group(
AddIndex,
"户号",
{{"所有记录", each _, type table [户号 = Int64.Type, 姓名 = nullable text, Index = Int64.Type]}}
),
EnsureFourRows = (tbl as table) as table =>
let
RowCount = Table.RowCount(tbl),
RowsToAdd =
if RowCount < 4 then
List.Repeat({[户号 = tbl[户号]{0}, 姓名 = null, Index = null]}, 4 - RowCount)
else
{},
ResultTable = Table.Combine({tbl, Table.FromRecords(RowsToAdd)})
in
ResultTable,
EnsuredFourRows = Table.TransformColumns(Grouped, {"所有记录", each EnsureFourRows(_)}),
Expanded = Table.ExpandTableColumn(EnsuredFourRows, "所有记录", {"姓名"})
in
Expanded |
|