Forum Discussion
MagikJukas
Resolver III
2 years agoMerge table in loop
Hello, assuming I have a table like this: Father Son A B B C C D D E E F F G G H I would like to merge this table to obtain: Father Son A B A ...
- 2 years ago
let Source = your_table, rec = Record.FromList(Source[Son], Source[Father]), back_to_back = (s, name) => [next_name = Record.FieldOrDefault(rec, name), next = if next_name is null then s else @back_to_back(s & {next_name}, next_name)][next], add_col = Table.AddColumn(Table.RemoveColumns(Source, {"Son"}), "Son", (x) => back_to_back({}, x[Father])), expand = Table.ExpandListColumn(add_col, "Son") in expand
AlienSx
Super User
2 years agolet
Source = your_table,
rec = Record.FromList(Source[Son], Source[Father]),
back_to_back = (s, name) =>
[next_name = Record.FieldOrDefault(rec, name),
next = if next_name is null then s else @back_to_back(s & {next_name}, next_name)][next],
add_col = Table.AddColumn(Table.RemoveColumns(Source, {"Son"}), "Son", (x) => back_to_back({}, x[Father])),
expand = Table.ExpandListColumn(add_col, "Son")
in
expand